- 在本地
~/.ssh
文件夹生成公私钥对:
id_rsa; id_rsa.pub. 将id_rsa.pub内容复制到服务器 ~/.ssh/authorized_keys文件
- 本地~/.ssh中创建config
Host cloud
HostName 8.129.49.94
User zhiyuan
Port 22
#IdentityFile ~/.ssh/id_rsa # 都可以
PubkeyAuthentication yes
Host local
HostName 192.168.107.128
User zhiyuan
Port 22
IdentityFile ~/.ssh/id_rsa
当配置完后仍需要密码时:
# 1. 服务端查看系统日志文件
trail /var/log/secure (-n 20可选)
# Authentication refused: bad ownership or modes for file
# 2. 修改目录, 文件权限
chmod g-w /home/zhiyuan
chmod 700 /home/zhiyuan/.ssh
chmod 600 /home/zhiyuan/.ssh/authorized_keys