1、制作密钥对

包含公钥和私钥,可以在linux上使用 ssh-keygen 命令或 puttygen.exe 工具进行生成。

2、在服务器上设置公钥

cd .ssh
cat id_rsa.pub >> authorized_keys

如提示没有该目录可以进行新建
mkdir .ssh

设置权限
chmod 600 authorized_keys
chmod 700 ~/.ssh

3、设置 SSH,打开密钥登录功能

vim /etc/ssh/sshd_config

开启

RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes
PasswordAuthentication no
StrictModes no

重启SSH服务

Debian/Ubuntu执行:
/etc/init.d/ssh restart
CentOS执行:
/etc/init.d/sshd restart