大多数企业都用口令来认证登录,少部分企业用密钥来认证

[root@WebServer ~]# rpm -qa openssh openssl       

openssh-5.3p1-112.el6_7.x86_64

openssl-1.0.1e-42.el6.x86_64


如果没有安装就安装一下

[root@WebServer ~]# yum install -y openss*


SSH服务器分发管理A—>B和A---C同时

[root@A ~]# useradd bier

[root@A ~]# id bier

uid=807(bier) gid=807(bier) groups=807(bier)

[root@A ~]# echo "bier:123456" |chpasswd

[root@A ~]# su - bier

[bier@A ~]$


创建私钥和公钥

[bier@A ~]$ ssh-keygen -t dsa    后面直接回车不需要设置密码

Your identification has been saved in /home/bier/.ssh/id_dsa.

Your public key has been saved in /home/bier/.ssh/id_dsa.pub.


私钥的权限是600 ,公钥是644


[bier@A .ssh]$ pwd

/home/bier/.ssh

[bier@A .ssh]$ ll

total 8

-rw------- 1 bier bier 668 Dec  9 20:53 id_dsa  生成的私钥

-rw-r--r-- 1 bier bier 599 Dec  9 20:53 id_dsa.pub   和公钥


把公钥拷贝到远程机器上

[bier@A ~]$ ssh-copy-id  -i .ssh/id_dsa.pub "-p22 bier@192.168.1.139"


The authenticity of host '192.168.1.139 (192.168.1.139)' can't be established.

RSA key fingerprint is c5:29:26:e0:a5:02:f8:10:73:b8:6a:e9:ec:14:1f:0f.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.1.139' (RSA) to the list of known hosts.

bier@192.168.1.139's password: 

Now try logging into the machine, with "ssh '-p22 bier@192.168.1.139'", and check in:

  .ssh/authorized_keys


上面是发送公钥到远程机器上,指定远程的端口的写法,出现下面的字样说明发送成功,默认写法是

ssh-copy-id –i  .ssh/id_dsa.pub bier@10.0.0.8

发送到远程机器上名称改变成authorized_keys



这时连接不需要密码了

[bier@A ~]$ ssh -p22 bier@192.168.1.139   执行这步就可以远程

[bier@B ~]$  ===>此时已经登录到B机器了



不远程连接进去执行命令,这些都是对对应用户的远程操作

[bier@A ~]$ ssh -p22 bier@192.168.1.139 /sbin/ifconfig



免密码登录小结:

1.免密码登录验证是单向的操作。

2.基于用户的,最好不要夸不同的用户

3.ssh连接慢的问题

4.批量分发1000台初始都需要输入一次密码,并且第一次连接要确认(expect实现)。