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