建立公钥私钥,分别创建两个用户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
SSH公钥复制教程
本文详细介绍了如何在两个用户之间通过SSH协议复制公钥,实现无密码登录。具体步骤包括使用ssh-copy-id命令从源用户向目标用户传输公钥,并解决权限问题。
284

被折叠的 条评论
为什么被折叠?



