由于每次密码验证登陆到另外的linux主机要输入密码,如果太多次数烦不胜烦,因此配置dsa认证,免去繁琐的输入密码。配置rsa、dsa方法完全一样,此处以dsa为例!
系统环境:
中心分发服务器hostname:SSH-MASTER #IP:192.168.199.171/24 Centos 6.4 2.6.32-358.el6.x86_64
公匙接收服务器hostname:SSH-CLIENT-NO01 #192.168.199.172/24 Centos 6.4 2.6.32-358.el6.x86_64
公匙接收服务器hostname:SSH-CLIENT-NO02 #192.168.199.53/24 Centos 5.3 2.6.18-128.el5 x86_64SourceByrd's Weblog-https://note.t4x.org/basic/centos-ssh-dsa/
试验过程:SourceByrd's Weblog-https://note.t4x.org/basic/centos-ssh-dsa/
方法1:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
[byrd@SSH-MASTER ~]$ su - byrd Password: [byrd@SSH-MASTER ~]$ ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (/home/byrd/.ssh/id_dsa): #默认回车即可,不修改key的位置 Created directory '/home/byrd/.ssh'. Enter passphrase (empty for no passphrase): #设置登录到公匙接收服务器的密码,最少4位,不设置回车跳过 Enter same passphrase again: Your identification has been saved in /home/byrd/.ssh/id_dsa. #建立私钥 Your public key has been saved in /home/byrd/.ssh/id_dsa.pub. #建立公钥 The key fingerprint is: ca:65:b4:76:99:fa:c6:6e:c0:19:97:1f:38:db:ee:19 byrd@SSH-MASTER The key's randomart image is: +--[ DSA 1024]----+ | | | . | | . . = | | ...oyo o | | .S++. o | | . =+o . .E | | o .0 ...| | .+ ..| | +o | +-----------------+ [byrd@SSH-MASTER ~]$ cd .ssh/ [byrd@SSH-MASTER .ssh]$ ll -al total 16 -rw-------. 1 byrd byrd 668 Apr 20 11:36 id_dsa #私钥 -rw-r--r--. 1 byrd byrd 605 Apr 20 11:36 id_dsa.pub #公钥 [byrd@SSH-MASTER .ssh]$ ssh-copy-id -i id_dsa.pub "-p 22 byrd@192.168.199.53" The authenticity of host '192.168.199.53 (192.168.199.53)' can't be established. RSA key fingerprint is c7:6c:a4:98:e3:91:81:21:f6:c7:9a:5a:1e:bd:53:0a. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.199.53' (RSA) to the list of known hosts. byrd@192.168.199.53's password: Now try logging into the machine, with "ssh '-p 22 byrd@192.168.199.53'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [byrd@SSH-MASTER .ssh]$ ssh -p22 byrd@192.168.199.53 [byrd@SSH-CLIENT-NO02 ~]$ exit logout Connection to 192.168.199.53 closed. 如果创建密匙时设置了密码登陆时是这样: [byrd@SSH-MASTER .ssh]$ ssh -p22 byrd@192.168.199.53 Enter passphrase for key '/home/byrd/.ssh/id_dsa': Last login: Sun Apr 20 20:46:42 2014 from 192.168.199.53 [byrd@SSH-CLIENT-NO02 ~]$ exit logout Connection to 192.168.199.53 closed. [byrd@SSH-MASTER .ssh]$ |
方法2:SourceByrd's Weblog-https://note.t4x.org/basic/centos-ssh-dsa/
接收端:
0 1 2 3 4 5 |
[byrd@SSH-CLIENT-NO01 ~]$ mkdir .ssh [byrd@SSH-CLIENT-NO01 ~]$ ls -al drwxrwxr-x. 2 byrd byrd 4096 Apr 20 11:42 .ssh [byrd@SSH-CLIENT-NO01 ~]$ chmod 700 .ssh #如果不修改,当中心分发连接的时候会要密码。key失效! [byrd@SSH-CLIENT-NO01 ~]$ ls -al drwx------. 2 byrd byrd 4096 Apr 20 11:42 .ssh |
分发端:
0 1 2 3 4 5 6 |
[byrd@SSH-MASTER .ssh]$ scp /home/byrd/.ssh/id_dsa.pub byrd@192.168.199.172:/home/byrd/.ssh/authorized_keys The authenticity of host '192.168.199.172 (192.168.199.172)' can't be established. RSA key fingerprint is 05:35:2b:f8:34:n1:c7:4b:27:2b:34:e4:90:1c:0d:fc. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.199.172' (RSA) to the list of known hosts. byrd@192.168.199.172's password: id_dsa.pub 100% 605 0.6KB/s 00:00 |
接收端:
0 1 2 3 4 |
[byrd@SSH-CLIENT-NO01 .ssh]$ ls -al -rw-r--r--. 1 byrd byrd 605 Apr 20 11:51 authorized_keys [byrd@SSH-CLIENT-NO01 .ssh]$ chmod 600 authorized_keys #建议修改为600,经过测试不修改也没有关系 [byrd@SSH-CLIENT-NO01 .ssh]$ ls -al -rw-------. 1 byrd byrd 605 Apr 20 11:51 authorized_keys |
分发端:
0 1 2 3 4 5 |
[byrd@SSH-MASTER .ssh]$ ssh -p22 byrd@192.168.199.172 ls -l /tmp/192.168.199.172.txt -rw-rw-r--. 1 byrd byrd 0 Apr 20 12:02 /tmp/192.168.199.172.txt [byrd@SSH-MASTER .ssh]$ ssh -p22 byrd@192.168.199.172 [byrd@SSH-CLIENT-NO01 ~]$ exit logout Connection to 192.168.199.172 closed. |
备注:略SourceByrd's Weblog-https://note.t4x.org/basic/centos-ssh-dsa/
申明:本文由BYRD原创(基于Centos6.4 X64、Centos5.3 X64),未经许可禁止转载!SourceByrd's Weblog-https://note.t4x.org/basic/centos-ssh-dsa/ SourceByrd's Weblog-https://note.t4x.org/basic/centos-ssh-dsa/