Linuxのssh設定

何回もやることだからメモします。

鍵ペアをクライアント側で作成

cd ~/.ssh
# -f 名前指定
ssh-keygen -t rsa -f a1yama_rsa

Enter!!

Enter!!


スポンサーリンク





公開鍵をサーバーへ

$ scp a1yama_rsa.pub root@remoteserver.com:~/

サーバにログイン

ssh root@remoteserver.com

公開鍵を~/.ssh/authorized_keysに置く

cd ~/.ssh
cat a1yama_rsa.pub > authorized_keys
# パーミッション変更
chmod 600 authorized_keys

クライアント側のconfigに登録

vim ~/.ssh/config


Host hoge
User hogeuser
HostName remoteserver.com
IdentityFile ~/.ssh/a1yama_rsa

これでこんな感じでログインできる

ssh hoge

ログイン出来ない場合は.sshディレクトリのパーミッションを700にしてください。

chmod 700 ~/.ssh

参照

akiniwa.hatenablog.jp