ssh root@127.0.0.1 需要登陆密码
ssh-keygen 生成公钥和私钥 可以去.ssh 查看是否有两个文件 id_rsa id_rsa.pub
ssh-copy-id root(注释:访问者的密码)@127.0.0.1 复制公钥到远程服务器 可以去.ssh 查看是否有 authorized_keys
ssh root@127.0.0.1 不需要登陆密码了
例:
[root@localhost ~]# ls -a
. .bash_logout .config Documents initial-setup-ks.cfg Pictures Templates
.. .bash_profile .cshrc Downloads .local Public Videos
anaconda-ks.cfg .bashrc .dbus .esd_auth Music .ssh .Xauthority
.bash_history .cache Desktop .ICEauthority original-ks.cfg .tcshrc
[root@localhost ~]# cd .ssh
[root@localhost .ssh]# ls
id_rsa id_rsa.pub
[root@localhost .ssh]# ssh-copy-id root@127.0.0.1
/usr/bin/ssh-copy-id: INFO: attempting to log in 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@127.0.0.1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@127.0.0.1'"
and check to make sure that only the key(s) you wanted were added.
[root@localhost .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
[root@localhost .ssh]#