0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Githubの作業をSSHで行う

Last updated at Posted at 2017-05-15

httpsで作業したほうが楽な時もあるかと思いますが、2段階認証(two factor authentication(略して2FA))などを設定するとSSHのほうが楽になると思ったので、設定方法を備忘録的に書きます。

複数のアカウントを使う場合の設定となります。1個だけの設定なら簡単なはずです。
(cloneするときに、自動でサイトごとの暗号化キーが使われるようにします。)

今回は、githubとgitlab的な感じで、サーバーが違って、アカウントも違うという、シンプルな複数アカウント設定の場合を想定します。

鍵の作り方と公開キーの設定の仕方


Github help

英語だけど、↑を見てください。(見ればコピペでいけるはず。。。)
(手順には書いてないですが、暗号キーの権限設定を変えておいたほうが良いです。)

chmod 600 id_rsa

作成後

id_rsa
id_rsa.pub

ができるので、分かりやすいように別名をつけます。

変更後

cd ~/.ssh/config
mv id_rsa      id_rsa_github
mv id_rsa.pub  id_rsa_github.pub

~/.ssh/configを作成する


~/.ssh/config

Host host-hoge
    HostName github.com
    User hoge
    IdentityFile ~/.ssh/id_rsa_github
    Port 22
    IdentitiesOnly yes

Host 自由入力
    HostName remote先のhost名
    User ユーザ名
    IdentityFile 暗号キー
    Port サーバー側のポート
    IdentitiesOnly(キャッシュを使わずにキーを都度ファイルから読み取る)
chomd 600 ~/.ssh/config

cloneする場合


git clone git@host-hoge:hoge/hoge-repo.git

git clone git@[Host]:リポジトリ名.git

Host名は、なんでもよいのですが、今回の想定の場合、HostNameと合わせておくとGithubの画面からcloneコマンドをコピーした時と同じになるので楽です。

0
1
2

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?