[root@foundation ~]# ssh root@172.25.254.215 The authenticity of host '172.25.254.215 (172.25.254.215)' can't be established. ECDSA key fingerprint is 92:eb:ee:74:e9:5a:9d:68:90:25:bd:1f:aa:bb:b1:e0. Are you sure you want to continue connecting (yes/no)? yes ##建立安全传输key Warning: Permanently added '172.25.254.215' (ECDSA) to the list of known hosts. root@172.25.254.215's password: ##密码输入没有回显 Last login: Tue Feb 9 16:43:03 2016 from foundation.ilt.example.com [root@localhost ~]# vim /etc/motd ##设定登陆显示字符 wellcome to login ! [root@localhost ~]# logout Connection to 172.25.254.215 closed. [root@foundation ~]# ssh root@172.25.254.215 root@172.25.254.215's password: Last login: Tue Feb 9 16:59:38 2016 from foundation.ilt.example.com wellcome to login ! [root@localhost ~]# ##登陆成功 ctrl +d | logout ##退出
[root@foundation ~]# ssh-keygen ##生成公钥和私钥的工具 Generating public/private rsa key pair. Enter file inwhich to save the key (/root/.ssh/id_rsa): 『enter』 ##指定加密字符保存文件,使用默认 Enter passphrase (empty for no passphrase): ##密码,必须大于4位,可以为空 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: 25:04:85:e5:cd:dd:cf:ac:e4:70:ec:3f:5e:4e:59:7d root@foundation.ilt.example.com The key's randomart image is: +--[ RSA 2048]----+ | .=+ | | .o o . . | | o + . . | | o . +.| | S . + E| | * .+| | +.o| | =.| | ..+| +-----------------+ [root@foundation ~]# cd ~/.ssh/ [root@foundation .ssh]# ll total 12 -rw------- 1 root root 1679 Feb 9 17:23 id_rsa ##私钥 -rw-r--r-- 1 root root 413 Feb 9 17:23 id_rsa.pub ##公钥 -rw-r--r-- 1 root root 757 Feb 9 16:59 known_hosts ##此文件记录了ssh所连接过的主机信息。 [root@foundation .ssh]# pwd ##生成密钥的存放位置 /root/.ssh
[root@foundation ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.215 /usr/bin/ssh-copy-id: INFO: attempting to login with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@172.25.254.215's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@172.25.254.215'" and check to make sure that only the key(s) you wanted were added. [root@foundation ~]# ssh root@172.25.254.215 Last login: Tue Feb 9 18:08:24 2016 from foundation.ilt.example.com wellcome to login ! [root@localhost ~]# ll .ssh/ total 4 -rw-------. 1 root root 413 Feb 9 18:11 authorized_keys ##此文件在目标用户加目录的.ssh中,这个文件就是目标用户被加密的标识,文件内容为公钥内容