ssh无密码登陆服务器

网上该类教程很多,但还是记录下,方便以后查询的时候使用。

两台服务器,内网ip分别是:

172.16.3.91 (本地机)

172.16.3.92 (远程机)

现在想在本地机上通过ssh 172.16.3.92登陆到远程机而不需要密码。


1.在本地机上用ssh-keygen 创建公钥私钥。

[root@rs-1 ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

dc:fc:ea:b8:bb:74:d7:75:4b:6a:27:82:28:27:be:d6 root@rs-1


这个过程会提示输入密码,记住直接按回车就行,不要输入密码!要是输入了密码,一会访问的时候就需要输入密码了。

创建之后能看到如下两个文件

[root@rs-1 .ssh]# ll

total 24

-rw------- 1 root root 1675 May  8 07:18 id_rsa

-rw-r--r-- 1 root root  391 May  8 07:18 id_rsa.pub


id_rsa是私钥

id_rsa.pub是公钥, 主要给远程机使用的


2.把公钥传到远程机上去。

[root@rs-1 .ssh]# scp id_rsa.pub root@172.16.3.92:~/.ssh/authorized_keys

Address 172.16.3.92 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

root@172.16.3.92's password: 

id_rsa.pub                                                                                                                                  100%  391     0.4KB/s   00:00    


3.ssh链接时候就不需要密码了,直接登陆到远程机

[root@rs-1 .ssh]# ssh 172.16.3.92

Address 172.16.3.92 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

Last login: Thu May  8 07:19:28 2014 from 172.16.3.91

[root@rs-2 ~]# 




参考:http://blog.csdn.net/gongqingkui/article/details/9023439

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值