Linuxユーザーの追加 SSH公開鍵で接続する。

sshの設定、必須な割には度々忘れるのでメモをしておく。

Userの追加

sudo -s

root ユーザーになっておく。

useradd new_user
passwd new_user
su new_user

Keyの設置

~/.ssh/authorized_keys

ユーザーフォルダの配下にauthorized_keysを設置する。

パスワードログインの禁止

/etc/ssh/sshd_config
PasswordAuthentication no

noに変更。

# service sshd restart

serviceを再起動する。

Permission denied のエラーが発生する。

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
/home/user/.ssh は 0700
/home/user/.ssh/authorized_keys は 0600

エラーが発生した場合は上記のパーミションと所有者を確認する。

chmod -R 700 <user>/.ssh/
chmod 600 <user>/.ssh/authorized_keys
chown -R  new_user <user>/.ssh/