实现任意机器间均非输入密码进行SSH登录

实现原理:
在本机A上执行“ssh-keygen -b 1024 -t rsa”命令,就会生成公钥证书“id_rsa.pub”,
在远程机器B的路径/home/autoxj1/.ssh/下新建文件“authorized_keys”,
然后将机器A上生成的公钥证书中的文字内容copy到机器B的文件“authorized_keys”里面即可。
--------------------------------
举一反三:假如要想在机器X、机器Y、机器Z、机器W间均实现任意两台机器间均可以非输入密码进行登录,应该如何操作?
具体操作方法:
步骤1:分别在机器X、机器Y、机器Z、机器W执行“ssh-keygen  -b  1024  -t  rsa”命令,生成公钥证书“id_rsa.pub”;
步骤2:分别将机器X、机器Y、机器Z、机器W的公钥证书“id_rsa.pub”内容全部粘贴到新建文件“authorized_keys”中;
步骤3:将新建文件“authorized_keys”分别复制到机器X、机器Y、机器Z、机器W的/home/autoxj1/.ssh/下;
===================================================================================================================================

在远程服务器上新增客户端机器公钥证书文件的场合,
使用下面的(一)和(二)操作来完成:

(一)在LNSY-PS-YDSMJS-WEB01机器的autoxj1用户下,生成证书并将公钥证书放到LNSY-PS-YDSMJS-WEB02机器上,
      从而可以时间在LNSY-PS-YDSMJS-WEB01机器的autoxj1用户下可以免密码ssh登录到LNSY-PS-YDSMJS-WEB02机器。
      具体操作如下:
--------------------------------------------------------------
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$ pwd
/home/autoxj1
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$ whoami
autoxj1
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$ ll
总计 0
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$ ls -al
总计 40
drwx------  4 autoxj1 mpsp    4096 05-06 11:35 .
drwxr-xr-x 11 root    root    4096 05-05 14:16 ..
-rw-------  1 autoxj1 autoxj1  478 05-06 11:39 .bash_history
-rw-r--r--  1 autoxj1 autoxj1   33 05-05 14:16 .bash_logout
-rw-r--r--  1 autoxj1 autoxj1  176 05-05 14:16 .bash_profile
-rw-r--r--  1 autoxj1 autoxj1  124 05-05 14:16 .bashrc
-rw-r--r--  1 autoxj1 autoxj1  515 05-05 14:16 .emacs
drwxr-xr-x  4 autoxj1 autoxj1 4096 05-05 14:16 .mozilla
drwx------  2 autoxj1 mpsp    4096 05-06 11:35 .ssh
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$ ssh-keygen  -b  1024  -t  rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/autoxj1/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/autoxj1/.ssh/id_rsa.
Your public key has been saved in /home/autoxj1/.ssh/id_rsa.pub.
The key fingerprint is:
c3:6c:ae:c6:12:d3:77:14:82:b1:fd:ab:5b:4b:f7:3a autoxj1@LNSY-PS-YDSMJS-WEB01
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$ ls -al
总计 40
drwx------  4 autoxj1 mpsp    4096 05-06 11:35 .
drwxr-xr-x 11 root    root    4096 05-05 14:16 ..
-rw-------  1 autoxj1 autoxj1  478 05-06 11:39 .bash_history
-rw-r--r--  1 autoxj1 autoxj1   33 05-05 14:16 .bash_logout
-rw-r--r--  1 autoxj1 autoxj1  176 05-05 14:16 .bash_profile
-rw-r--r--  1 autoxj1 autoxj1  124 05-05 14:16 .bashrc
-rw-r--r--  1 autoxj1 autoxj1  515 05-05 14:16 .emacs
drwxr-xr-x  4 autoxj1 autoxj1 4096 05-05 14:16 .mozilla
drwx------  2 autoxj1 mpsp    4096 05-06 11:52 .ssh
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$ cd /home/autoxj1/.ssh/
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ ll
总计 12
-rw------- 1 autoxj1 mpsp  887 05-06 11:52 id_rsa
-rw-r--r-- 1 autoxj1 mpsp  238 05-06 11:52 id_rsa.pub
-rw-r--r-- 1 autoxj1 mpsp 1182 05-06 11:36 known_hosts
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ pwd
/home/autoxj1/.ssh
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ more id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAwgTOZTHEaYMESc8vA6MBNob1lLLydbPQeAptj5VX5M21Xe+8gsIIAHd3IVcoh4a9zf7je1A9vbBHN1Chc9MhMkn4lA7XxbhR41lE+Wml6F2mO728kBKQxk159EUDbjqOkp5UxjhGcuStJWRsoBvAj2UrMYPbeA1oU56Sj/CNkkE= autoxj1@LNSY-PS-YDSMJS-WEB01
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ scp id_rsa.pub  autoxj1@172.17.1.200:/home/autoxj1/.ssh/
 Authorized users only. All activity may be monitored and reported
autoxj1@172.17.1.200's password:
id_rsa.pub      100%  238     0.2KB/s   00:00
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ ssh autoxj1@172.17.1.200
 Authorized users only. All activity may be monitored and reported
autoxj1@172.17.1.200's password:
Last login: Wed May  6 12:08:27 2015 from 172.17.1.201
 Authorized users only. All activity may be monitored and reported
[autoxj1@LNSY-PS-YDSMJS-WEB02 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 ~]$ cd /home/autoxj1/.ssh/
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ ll
总计 8
-rw-r--r-- 1 autoxj1 mpsp 238 05-06 12:11 id_rsa.pub
-rw-r--r-- 1 autoxj1 mpsp 394 05-06 11:35 known_hosts
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ mv  id_rsa.pub  authorized_keys
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ ll
总计 8
-rw-r--r-- 1 autoxj1 mpsp 238 05-06 12:11 authorized_keys
-rw-r--r-- 1 autoxj1 mpsp 394 05-06 11:35 known_hosts
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ exit
logout
Connection to 172.17.1.200 closed.
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ ssh autoxj1@172.17.1.200
 Authorized users only. All activity may be monitored and reported
Last login: Wed May  6 12:11:20 2015 from 172.17.1.201
 Authorized users only. All activity may be monitored and reported
[autoxj1@LNSY-PS-YDSMJS-WEB02 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 ~]$
==========================================================================================================================================
==========================================================================================================================================
==========================================================================================================================================


(二)在LNSY-PS-YDSMJS-WEB02机器的autoxj1用户下,生成证书并将公钥证书放到LNSY-PS-YDSMJS-WEB01机器上,
      从而可以时间在LNSY-PS-YDSMJS-WEB02机器的autoxj1用户下可以免密码ssh登录到LNSY-PS-YDSMJS-WEB01机器。
      具体操作如下:
--------------------------------------------------------------
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ whoami
autoxj1
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ pwd
/home/autoxj1/.ssh
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ ll
总计 8
-rw-r--r-- 1 autoxj1 mpsp 238 05-06 12:11 authorized_keys
-rw-r--r-- 1 autoxj1 mpsp 394 05-06 11:35 known_hosts
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ ssh-keygen  -b  1024  -t  rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/autoxj1/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/autoxj1/.ssh/id_rsa.
Your public key has been saved in /home/autoxj1/.ssh/id_rsa.pub.
The key fingerprint is:
de:47:68:e8:c2:eb:a5:8a:d3:a3:6a:29:4f:86:9d:57 autoxj1@LNSY-PS-YDSMJS-WEB02
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ ll
总计 16
-rw-r--r-- 1 autoxj1 mpsp 238 05-06 12:11 authorized_keys
-rw------- 1 autoxj1 mpsp 887 05-06 14:48 id_rsa
-rw-r--r-- 1 autoxj1 mpsp 238 05-06 14:48 id_rsa.pub
-rw-r--r-- 1 autoxj1 mpsp 394 05-06 11:35 known_hosts
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ scp id_rsa.pub autoxj1@172.17.1.201:/home/autoxj1/.ssh/authorized_keys
 Authorized users only. All activity may be monitored and reported
autoxj1@172.17.1.201's password:
id_rsa.pub               100%  238     0.2KB/s   00:00
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB02 .ssh]$ ssh autoxj1@172.17.1.201
 Authorized users only. All activity may be monitored and reported
Last login: Wed May  6 14:53:07 2015 from 172.17.1.201
 Authorized users only. All activity may be monitored and reported
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 ~]$ cd /home/autoxj1/.ssh/
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ ll
总计 16
-rw-r--r-- 1 autoxj1 mpsp  238 05-06 14:56 authorized_keys
-rw------- 1 autoxj1 mpsp  887 05-06 11:52 id_rsa
-rw-r--r-- 1 autoxj1 mpsp  238 05-06 11:52 id_rsa.pub
-rw-r--r-- 1 autoxj1 mpsp 1576 05-06 11:57 known_hosts
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ date
2015年 05月 06日 星期三 14:57:01 CST
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$ more authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAyzCbRXlidc7I9Y67OJC15zBxe4KiC3e0vMgeCb5dSfAHZUwgKjF5opwN+qJ3NL+uRaN8i1GkTztHUgBLLIwOumAEwPINx/bzBqkLq8BWKLOZ2yDojKP4Mh0JpIOA8E3IH6PGMAluJnK7/L8gZcTm9Vg52ja85G2bqdGvF0fXPvk= autoxj1@LNSY-PS-YDSMJS-WEB02
[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$

[autoxj1@LNSY-PS-YDSMJS-WEB01 .ssh]$


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值