在本地在 ~/.ssh目录生成密钥
#ssh-keygen
一路回车
运行结束以后, 默认在 ~/.ssh目录生成两个文件:
id_rsa :私钥
id_rsa.pub :公钥
导入公钥到认证文件,更改权限
先导入本机:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
再导入服务器:
scp {-P port} ~/.ssh/id_rsa.pub glowd@host:~
在服务器上:
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
最后,更改服务器上的权限:
chmod 755 ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys