码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS 6.4配置SSH免密码验证

时间:2015-05-04 15:54:05      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:centos 6.4配置ssh免密码验证

一、环境

    CentOS 6.4x64位

    zabbix-c1:192.168.3.29

    zabbix-c2:192.168.3.30


二、配置从zabbix-c1进行ssh到zabbix-c2免密码验证


    在zabbix-c1上生成密钥对,整个过程回车即可。

[root@zabbix-c1 ~]# ssh-keygen 
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:
7d:ca:81:d9:35:c5:ab:7b:93:f0:b8:0f:8a:e8:63:c2 root@zabbix-c1
The key‘s randomart image is:
+--[ RSA 2048]----+
|             ..  |
|             ..  |
|            o  . |
|         = . ..  |
|        S + ..   |
|         . +o    |
|   .      o .= . |
|    E o. . .o.=  |
|     +o.. . .+.. |
+-----------------+

    在/root/.ssh目录下回生成私钥(id_rsa)和公钥(id_rsa.pub)

[root@zabbix-c1 ~]# ll /root/.ssh/
total 12
-rw------- 1 root root 1675 May  4 09:31 id_rsa            #私钥
-rw-r--r-- 1 root root  396 May  4 09:31 id_rsa.pub        #公钥
-rw-r--r-- 1 root root  394 Apr 30 10:29 known_hosts


三、将公钥复制到目标机器(zabbix-c2)的authorized_keys文件中

[root@zabbix-c1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.3.30
root@192.168.3.30‘s password:         #这里在第一次连接的时候需要输入密码
Now try logging into the machine, with "ssh ‘192.168.3.30‘", and check in:

  .ssh/authorized_keys

to make sure we haven‘t added extra keys that you weren‘t expecting.


#使用ssh登陆到zabbix-c2机器上,整个过程不需要输入密码
[root@zabbix-c1 ~]# ssh 192.168.3.30
Last login: Mon May  4 09:24:02 2015 from 192.168.3.2
[root@zabbix-c2 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:68:fd:3e brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.30/24 brd 192.168.3.255 scope global eth0
    inet6 fe80::20c:29ff:fe68:fd3e/64 scope link 
       valid_lft forever preferred_lft forever
[root@zabbix-c2 ~]# hostname
zabbix-c2


四、使用ssh协议远程执行命令

#远程查看内存信息
[root@zabbix-c1 ~]# ssh 192.168.3.30 free -m
             total       used       free     shared    buffers     cached
Mem:           988        121        867          0          8         44
-/+ buffers/cache:         68        919
Swap:         1999          0       1999

#远程查看iptables信息
[root@zabbix-c1 ~]# ssh 192.168.3.30 iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 10050:10051 
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

#远程查看IP地址信息
[root@zabbix-c1 ~]# ssh 192.168.3.30 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:68:fd:3e brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.30/24 brd 192.168.3.255 scope global eth0
    inet6 fe80::20c:29ff:fe68:fd3e/64 scope link 
       valid_lft forever preferred_lft forever

#远程查看hostname信息
[root@zabbix-c1 ~]# ssh 192.168.3.30 hostname
zabbix-c2


本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1641591

CentOS 6.4配置SSH免密码验证

标签:centos 6.4配置ssh免密码验证

原文地址:http://ly36843.blog.51cto.com/3120113/1641591

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!