生成密钥对
ssh-keygen -t rsa
拷贝到远程主机
#copy to remote by hand
$ cat ~/.ssh/[id_rsa].pub | ssh [user]@host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
# change authorized_keys permission
chmod 644 ~/.ssh/authorized_keys
#or
#copy with `ssh-copy-id`
ssh-copy-id -i id_rsa user@host
配置远程登陆
关闭密码登陆
vi /etc/ssh/sshd_config
PasswordAuthentication no