1. 在本机生成非对称密钥 local-user@local-machine:~/.ssh$ ssh-keygen -t rsa 三个输入分别是公私钥文件名、钥匙密码和确认密码,直接回车生成密钥id_rsa,公钥id_rsa.pub 2. 登录远程服务器,在用户的主目录下建立.ssh文件夹,如存在,跳过这一步 remote-user@remote-server:~$ mkdir .ssh remote-user@remote-server:~$ chmod 0700 .ssh 3. 在本机上将生成的公钥传送到远程服务器上面 local-user@local-machine:~/.ssh$ scp id_rsa.pub remote-user@remote-server.com:~/.ssh/id_rsa.pub 4. 登录远程服务器,将公钥加入认证列表 remote-user@remote-server:~/.ssh$ touch authorized_keys2 remote-user@remote-server:~/.ssh$ cat id_rsa.pub >> authorized_keys2 5. 最后回到本机,测试自动登录 local-user@local-machine:~$ ssh remote-server.com