centos7 设置ssh_key 无密码互信建立

建立公钥私钥,分别创建两个用户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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值