生成密钥:
[root@CentOS_105 ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 7f:f3:89:77:41:73:ee:ea:1c:fe:19:ff:ad:23:b4:3e root@CentOS_105 The key's randomart p_w_picpath is: +--[ RSA 2048]----+ | | | | | | | o.| | S ..o| | . . ..| | ..o..o.| | .E*ooB| | .o=OB*| +-----------------+
查看:
[root@CentOS_105 ~]# ll .ssh/ total 8 -rw-------. 1 root root 1675 Oct 23 06:52 id_rsa -rw-r--r--. 1 root root 397 Oct 23 06:52 id_rsa.pub [root@CentOS_105 ~]# cd .ssh/
将公钥写入认证文件:
[root@CentOS_105 .ssh]# cat id_rsa.pub >> authorized_keys
查看:
[root@CentOS_105 .ssh]# ll total 12 -rw-r--r--. 1 root root 397 Oct 23 06:54 authorized_keys -rw-------. 1 root root 1675 Oct 23 06:52 id_rsa -rw-r--r--. 1 root root 397 Oct 23 06:52 id_rsa.pub
赋予权限:
[root@CentOS_105 .ssh]# chmod 644 authorized_keys [root@CentOS_105 .ssh]# ll total 12 -rw-r--r--. 1 root root 397 Oct 23 06:54 authorized_keys -rw-------. 1 root root 1675 Oct 23 06:52 id_rsa -rw-r--r--. 1 root root 397 Oct 23 06:52 id_rsa.pub
模拟登录:
[root@CentOS_105 .ssh]# ssh CentOS_105 The authenticity of host 'centos_105 (192.168.0.105)' can't be established. ECDSA key fingerprint is 76:46:aa:90:04:2f:85:20:ee:a3:c9:1c:92:97:58:06. Are you sure you want to continue connecting (yes/no)? y Please type 'yes' or 'no': yes Warning: Permanently added 'centos_105,192.168.0.105' (ECDSA) to the list of known hosts. Last login: Sun Oct 23 06:34:04 2016 from 192.168.0.103 [root@CentOS_105 ~]# exit logout Connection to centos_105 closed. [root@CentOS_105 .ssh]#
第一次登录要输入yes/no确认连接.
转载于:https://blog.51cto.com/lybing/1894448