快速创建ssh互信

    由于工做中常常须要配置服务器之间的ssh互信.在网上找到好多关于ssh互信的配置方法,大多很麻烦,并且配置起来常常不成功.centos

    下面为介绍一种能够快速创建ssh互信的方法:安全

实验背景:服务器

使用的系统为CentOS 6.0ssh

两台服务器:ide

服务器A :地址192.168.26.134 新建用户redhat 密码: redhat ;spa

服务器B :地址192.168.26.135 新建用户centos 密码: centos ;3d

(出于安全考虑通常不配置root用户的ssh互信)xml

配置过程blog

----------------------------------------------------------------------------ci

一.配置服务器A:

1.用redhat用户登陆系统.或者su 到redhat用户.

2.生成私钥和公钥文件

  
  
  
  
  1. ssh-keygen -t rsa 

(注:这里不须要事先在家目录下创建 .ssh 文件夹)

回车后会显示以下内容:  (以后直接回车就能够了)

  
  
  
  
  1. Generating public/private rsa key pair. 
  2. Enter file in which to save the key (/home/redhat/.ssh/id_rsa):(回车) 
  3. Created directory '/home/redhat/.ssh'. //自动创建 .ssh文件夹 
  4. Enter passphrase (empty for no passphrase): (回车) 
  5. Enter same passphrase again: (回车) 

显示相似以下内容则代表私,公钥文件生成成功

3.将公钥拷贝到服务器B上

  
  
  
  
  1. ssh-copy-id -i .ssh/id_rsa.pub centos@192.168.26.135 

出现以下内容:

  
  
  
  
  1. The authenticity of host '192.168.26.135 (192.168.26.135)' can't be established. 
  2. RSA key fingerprint is 50:8b:93:c4:98:a9:ca:3d:44:68:9d:71:73:64:53:3e. 
  3. Are you sure you want to continue connecting (yes/no)? (这里输入yes) 

以后会让你输入服务器B上的用户的密码

  
  
  
  
  1. Warning: Permanently added '192.168.26.135' (RSA) to the list of known hosts. 
  2. centos@192.168.26.135's password: (输入centos用户的密码centos) 

最后显示以下内容表示拷贝成功:

4.验证ssh时是否还须要输入密码:

  
  
  
  
  1. ssh centos@192.168.26.135 -- 'whoami' 

  
  
  
  
  1. ssh-copy-id -i .ssh/id_rsa.pub redhat@192.168.26.134 

一切正常的话会直接显示centos用户的用户名

--------------------------------------------------------------------------- 

二.配置服务器B:

配置过程跟配置服务器A相同,这里简化描述,只描述步骤与命令.

1.登录服务器B 

2.生成密钥文件

  
  
  
  
  1. ssh-keygen -t rsa   

3.拷贝公钥文件服务器A

  
  
  
  
  1. ssh-copy-id -i .ssh/id_rsa.pub redhat@192.168.26.134 

4.验证

  
  
  
  
  1. ssh redhat@192.168.26.134 -- 'whoami' 

--------------------------------------------------------------------------

总结.到此服务器之间的ssh就创建好了.总的来讲创建互信只须要执行两条命令

  
  
  
  
  1. ssh-keygen -t rsa   
  2. ssh-copy-id -i .ssh/(公钥文件,以.pub结尾的文件) USER@(服务器地址) 

而不须要创建目录,修改权限,修改文件.

相关文章
相关标签/搜索