スキップしてメイン コンテンツに移動

投稿

ラベル(ssh)が付いた投稿を表示しています

1つのサーバーからGitHubの複数のプロジェクトにSSHの公開鍵を登録

秘密鍵と公開鍵のペアをリポジトリの数だけ作成。 $ ssh-keygen -t rsa -C "repo1" $ ssh-keygen -t rsa -C "repo2" 作成中にファイル名を指定できるので、それぞれの鍵にユニークな名前で作成。例えば下記のようにリポジトリの名前と紐づくように作成。 $ ~/.ssh/repo1_rsa $ ~/.ssh/repo2_rsa ~/.ssh/repo1_rsa,pub , ~/.ssh/repo2_rsa,pub の公開鍵の内容をGitHubのそれぞれのリポジトリの https://github.com/ima-create/{repojitory}/settings/keys で公開鍵を登録。 ~/.ssh/config ファイルに下記のように設定を記述。大事なのはHostの部分で{サブドメイン}.github.comとすること。 Host repo1.github.com HostName github.com User git IdentityFile ~/.ssh/repo1_rsa Host repo2.github.com HostName github.com User git IdentityFile ~/.ssh/repo2_rsa cloneするGitHubのリポジトリのURLに ~/.ssh/config ファイルで設定したサブドメインを含んだを指定すればSSHの認証が通ってクローンできる。 git clone git@repo1.github.com:{name}/{repogitory1}.git git clone git@repo2.github.com:{name}/{repogitory2}.git

Linuxで新規ユーザーとグループの追加とsshでpasswordなしでログインする方法

Linuxで新規ユーザーとグループの追加とsshでpasswordなしでログインする方法のメモです。super userで実施します。 ローカルホスト側: # user1でssh keyを生成した場合の例 $ ssh-keygen -t rsa Enter file in which to save the key (/home/user1/.ssh/id_rsa): Created directory '/home/user1/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/user1/.ssh/id_rsa. Your public key has been saved in /home/user1/.ssh/id_rsa.pub. ローカルホストのid_rsaはユーザーのみ読み書きできるように権限"600"を設定。 リモートホスト側: ユーザーとグループの追加 # "group1"をgroup id 100を指定して追加 $ groupadd group1 -g 100 # "user1"をuser id 200を指定して追加 $ useradd user1 -u 200 -g group1 # groupsコマンドでユーザーの所属グループを確認 $ groups user1 user1 : group1 リモートホスト側: sshでpasswordなしでログイン設定 # .sshディレクトリ作成 $ mkdir /home/user1/.ssh # [重要] .sshディレクトリの権限を変更 # "rwx------"か"rwxr-xr-x" 数字指定だと "700" か "755" でないとダメ。 $ chmod 700 /home/user1/.ssh # ログインするホストのユーザーのid_rsa.pubをauthorized_keysに追加 # 実際はssh-rsa