SSH无密码认证

方法一

192.168.0.140主机上执行

[root@localhost ~]# ssh-keygen -t rsa
或
[root@localhost ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
 
# 所有默认回车会在/root/.ssh/目录下生成两个文件:id_rsa(私钥,产生私钥的机子,即主动访问的机子拥有)、id_rsa.pub(公钥,发给被访问机子)。
 
[root@localhost ~]# cd .ssh/
[root@localhost .ssh]# ls
id_rsa  id_rsa.pub
  
# 本机SSH无密码验证
root@localhost:~/.ssh# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
 
此时ssh访问本机,就需要输入密码了,如下所示:
[root@localhost .ssh]# ssh 192.168.0.140
Address 192.168.0.140 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Last login: Wed Nov 19 23:12:21 2014 from 192.168.0.140
[root@localhost ~]# exit
logout
Connection to 192.168.0.140 closed.
 
将authorized_keys文件拷贝到192.168.0.141机器上
root@localhost:~/.ssh# scp /root/.ssh/id_rsa.pub root@192.168.0.141:/root/.ssh/

在192.168.0.141机器上执行以下命令

 # 准确地说,应该将id_rsa.pub拷贝到被访问机器上,并将公钥追加到授信文件authorized_keys里。
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
 
此时从192.168.0.140机器上SSH连接到192.168.0.141机器上就不需要密码了
[root@localhost .ssh]# ssh 192.168.0.141
Address 192.168.0.141 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Last login: Wed Nov 19 23:22:23 2014 from 192.168.0.11
[root@localhost ~]# exit
logout
Connection to 192.168.0.141 closed.

方法二

一种很简单的方法
192.168.0.140主机上执行

ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
ssh-copy-id root@192.168.0.141
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值