これまでVPSにパスワード認証で入っていたのでダサいと思い、公開鍵認証で入れるようにした。
その際1分くらいでできたのでそのときの手順をここに記す。
手順
- ターミナル.appを立ち上げる
- まずパスワード認証でVPSにログイン(ssh username@x.x.x.x)
- VPS上でmkdir .ssh
- chmod 700 .ssh/
- exit
- ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/Shotaro/.ssh/id_rsa): [enter]
Enter passphrase (empty for no passphrase): [パスフレーズ入力]
Enter same passphrase again: [パスフレーズ再入力]
その後・・・
- chmod 600 ~/.ssh/id_rsa.pub
- scp ~/.ssh/id_rsa.pub username@x.x.x.x:~/.ssh/authorized_keys
- ssh username@x.x.x.x
- パスフレーズを聞かれるので先ほど打ったパスレーズを入力してenter
- VPSにログイン成功
参考:公開鍵認証によるSSH接続 – Macターミナルの使い方