建立公钥私钥
,分别创建两个用户zhw与zhw2.
1.将zhw中生成的公钥(id_ras.pub)拷贝到zhw2中
[zhw@localhost ~]$ ssh-copy-id -i .ssh/id_rsa.pub zhw2@192.168.163.122 -p 4 4444
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for zhw:
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 2 key(s) remain to be installed -- if you are prompted n ow it is to install the new keys
zhw2@192.168.163.122's password:
Number of key(s) added: 2
Now try logging into the machine, with: "ssh -p '44444' 'zhw2@192.168.163.122' "
and check to make sure that only the key(s) you wanted were added.
2.将zhw2中生成的公钥(id_ras.pub)按步骤1拷贝到zhw1中
遇到问题
提示
/usr/bin/ssh-copy-id: ERROR: failed to open ID file ‘.ssh/id_rsa.pub’:
Permission denied
没权限,加sudo
[zhw@localhost ~]$ sudo ssh-copy-id -i .ssh/id_rsa zhw2@192.168.163.122 -p 44444
如果还需要输入密码,检查本用户下.ssh下文件的所属,可能被root了。
$ sudo chown user /home/user/.ssh/id_rsa
$ sudo chgrp user /home/user/.ssh/id_rsa
版权声明:本文为github_38854224原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。