如何使两台机器不通过密码连接起来(linux)

要求服务器10.96.22.40不通过密码直接连接服务器10.96.21.53

1:准备必须的软件

A:服务器40和53同时安装所需软件

yum -y install openssh-server openssh-clients

B:开启sshd服务

chkconfig sshd on
service sshd start

C:开启端口

/sbin/iptable -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
service iptables save

当然你也可以使22端口只接受某个ip的连接

/sbin/iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT
service iptables save

配置文件在: /etc/ssh/sshd config

英文地址:http://www.cyberciti.biz/faq/how-to-installing-and-using-ssh-client-server-in-linux/

2:部署

A:在40上创建公私密钥(不要更改生成的位置)【40上操作】

ssh-keygen -t rsa

B:复制公钥到53【40上操作】

cd /root/.ssh/
scp -P 60022 id_rsa.pub root@10.96.21.53:/root/.ssh/10.96.21.40

C:添加40的公钥到53的信任区域【53上操作】

cat 192.168.1.110 >> authorized_keys

D:启动sshd客户端【40上操作】

ssh-agent

F:添加id_rsa到ssh-agent(添加私钥到客户端)【40上操作】

ssh-add id_rsa

 

备注

(如果用户是空密码执行[passwd -d 用户名])

 (如果要是hadoop新用户不用密码在各服务器之间ssh需要每台服务器都建立新用户的不用密码登陆)

备注:你在40上重新创建密钥(ssh-keygen -t rsa)的话要重复2.A,B,C才行。

错误:

1:Permissions 0777 for '/root/.ssh/id_rsa' are too open.

处理办法:chmod 0600 /root/.ssh/id_rsa

 2:Could not open a connection to your authentication agent.

ssh-agent bash

ssh-add id_rsa

3:ssh: The authenticity of host 'hostname' can't be established

ssh -p 60022  -o StrictHostKeyChecking=no  10.96.16.119

4: snmp error的时候试试 service snmpd restart

posted @ 2013-07-11 18:14  李占卫  阅读(895)  评论(0编辑  收藏  举报