您的位置:首页 > 运维架构 > Linux

linux 免用户名登录 (RSA认证登录)

2011-04-12 14:43 253 查看
  在Linux运维中,经常需要写脚本。如何免用户名登录其他linux服务器是非常重要的。比如,输入 ssh root@192.168.1.1就能直接登录192.168.1.1

方法如下:

1、比如,我需要从192.168.1.2 登录192.168.1.1 ,那么我需要在192.168.1.2 执行

ssh-keygen -t rsa ,该命令以root用户执行。执行完毕后,会在/root/.ssh/目录下生成

id_rsa id_rsa.pub 两文件。

2、在192.168.1.1 /root/.ssh/ 目录下,建立文件 authorized_keys

如果没有该目录,请执行ssh-keygen -t rsa

3、将id_rsa.pub 中的内容复制到authorized_keys中去。

PS: 如果还有其他机器需要登录192.168.1.1,并且要求免用户名登录的话。只需要在本机生成rsa密钥,并且把pub(公钥)的内容添加到需要被登录的机器的authorized_keys中即可。

PS: 如果提示

IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

Someone could be eavesdropping on you right now (man-in-the-middle attack)!

It is also possible that the RSA host key has just been changed.

The fingerprint for the RSA key sent by the remote host is

44:c9:d4:86:d4:1d:bb:f7:7a:a0:9a:64:75:1e:29:55.

Please contact your system administrator.

Add correct host key in /root/.ssh/known_hosts to get rid of this message.

Offending key in /root/.ssh/known_hosts:12

RSA host key for 10.4.33.70 has changed and you have requested strict checking.

Host key verification failed.

那么请注意,那是因为以前有登陆信息保存在本机的know_hosts 内,保存的是对方的key,删除后即可登陆
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息