centos7 设置ssh_key 无密码互信建立

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_38854224/article/details/88425808

建立公钥私钥,分别创建两个用户zhw与zhw2.

1.将zhw中生成的公钥(id_ras.pub)拷贝到zhw2中

[zhw@localhost ~]$ ssh-copy-id -i .ssh/id_rsa.pub [email protected] -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
[email protected]'s password:

Number of key(s) added: 2

Now try logging into the machine, with:   "ssh -p '44444' '[email protected]'                                                               "
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 [email protected] -p 44444

如果还需要输入密码,检查本用户下.ssh下文件的所属,可能被root了。

$ sudo chown user /home/user/.ssh/id_rsa

$ sudo chgrp user /home/user/.ssh/id_rsa

猜你喜欢

转载自blog.csdn.net/github_38854224/article/details/88425808