linux机器之间ssh不用输密码的方法

作者:Admin    更新时间:2009-6-17 16:18:13

经过测试,以下步骤可以。
有两台机器linux1和linux2,想要从linux1进入linux2上,并且不用输入密码。
假设已经安装好了ssh,并且有两个用户user1@liunx1、user2@linux2。
1.以user1身份登陆linux1。执行:
  ssh-keygen -P "" -trsa1 -f ~/.ssh/identity
2.改变ssh配置文件/etc/ssh/ssh_config,添加
  Host *
        ForwardX11 yes
        IdentityFile ~/.ssh/identity
        Protocol 1
3.重启sshd
  /etc/rc.d/init.d/sshd restart
4.复制钥匙文件到linux2
  scp /home/user1/.ssh/identity.pub user2@linux2:/home/user2/.ssh/authorized_k
eys

  这样以后执行ssh或scp就可以不用输入密码了。
  如果还有其它的机器,比如想从linux1进入linux3也不用输入密码,把这个
identity.pub复制到linux3的/home/user3/.ssh/下并改名为authorized_keys就行了。
  如果想linux1进入linux1也不用输入密码,把/home/user1/.ssh/identity.pub的内容
添加在/home/user1/.ssh/authorized_keys中就行了。最后记得改变文件的权限:

5.改变文件权限
  chmod +600 /home/user1/.ssh/identity /home/user1/.ssh/identity.pub
6.以user2身份登陆linux2。
7.改变文件权限
  chmod +600 /home/user2/.ssh/authorized_keys

上一篇:网站安全堪忧,挂马、SQL注入,解决之道何在?
下一篇:LINUX操作系统下部署VPN服务器
网友评论
相关文章
站长推荐