0
0

More than 1 year has passed since last update.

localでGiteaセットアップ時にsshの使い方がわからなかったのでメモ

Last updated at Posted at 2022-10-31

GitHub触ってる時

自分のリポジトリに表示されてるCodeや、作った時のコマンドをそのままコピぺしてて理解してなかった

git@github.com:{ユーザー名}/{リポジトリ名}.git

状態

RaspberryPi

RaspberryPiにアクセスするためのconfigを別途設定済み ← これのせいでややこしい

~/.ssh/config
Host raspberry.local
        HostName raspberry.local
        User pi
        Port 22
        IdentityFile ~/.ssh/raspberry

Gitea

Docker Composeで立ててます

一応yamlファイル

compose.yaml
services:
  server:
    image: gitea/gitea
    restart: always
    volumes:
      - ./data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 3000:3000
      - 2222:22

ssh接続してみる(失敗)

Portは当然変更してるから、ssh git@raspberry.local:2222だとエラーが出る

> ssh git@raspberry.local:2222
ssh: Could not resolve hostname raspberry.local:2222: nodename nor servname provided, or not known

> ssh git@raspberry.local:2222:{ユーザー名}/{リポジトリ名}.git
ssh: Could not resolve hostname raspberry.local:2222:{ユーザー名}/{リポジトリ名}.git: nodename nor servname provided, or not known

そりゃ、コロン以降に、ユーザー名とリポジトリ名のパス書いてるからそうなるよね...
(ポートの識別できないし)

結局どうしたのか

  1. configを作る
  2. URLをconfigから認証するように変更する

だけ.

configを作る

~/.ssh/config
Host gitea
        HostName raspberry.local
        User git
        Port 2222
        IdentityFile ~/.ssh/raspberry-gitea

認証通るかテスト

> ssh gitea
PTY allocation request failed on channel 0
Hi there, {アカウント名}! You've successfully authenticated with the key named {認証鍵前}, but Gitea does not provide shell access.
If this is unexpected, please log in with password and setup Gitea under another user.
Connection to raspberry.local closed.

接続は通ったのでクリア

URLをconfigから認証するように変更する

giteaから適当なリポジトリに移動して、SSHのコマンドをコピー

sample
git@raspberry.local:{ユーザー名}/{リポジトリ名}.git

弄ってからコマンドをremote urlに登録

編集後
gitea:{ユーザー名}/{リポジトリ名}.git

最初のgiteaは、configで設定したHostのところと一致させればok!

> git remote add origin gitea:{ユーザー名}/{リポジトリ名}.git

そのまま、pushとか、pullしたら問題なく通るはず

まとめ

結局本体にアクセスするためにconfigのHostを使い切ったせいで、
今回別のHostを登録して、giteaに接続するためのURLも変える必要があった。

今回はconfigのホストに合わせて書き換えるという強行突破(?)で解決したけど、
コピペワンクリックでできなくなるのは面倒なので、下記のどっちかやっておけば良さそう

  1. 同じドメインで運用するのをやめる
  2. ラズパイにsshするときのHostを変える

ルーターの設定よくわからんので、個人的には後者が即実行できて無難
でもサブドメインでの運用とかできたらかっこいいよなぁ...笑

なんかもうちょい上手いやり方ありそうだけどね

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0