Linux 双机互信

环境:

192.168.75.128 redhat6.5 x86_64

192.168.75.130 redhat6.5 x86_64


一、在192.168.75.130上操作

1、在~/.ssh目录下产生公钥与私钥对.

# 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:

e4:bb:24:9c:f9:01:a8:80:4d:db:66:5b:47:48:c5:ca [email protected]

The key's randomart image is:

+--[ RSA 2048]----+

|      .o.        |

|     . ..        |

|  .  ...o        |

|.o o .E+         |

|o o = o S        |

| . + + = .       |

|  . . = +        |

|       + o       |

|        o        |

+-----------------+


2、ssh-copy-id 将公钥id_rsa.pub的内容追加到远程机器的 ~/ .ssh/authorized_key.文件中

# ssh-copy-id  -i ~/.ssh/id_rsa.pub 192.168.75.128  

[email protected]'s password: 

Now try logging into the machine, with "ssh '192.168.75.128'", and check in:


  .ssh/authorized_keys


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


3、登录到远程机器不用输入密码,登陆之后会将对方的信息,记录在known_hosts文件中,第一次登陆需要输入yes

# ssh 192.168.75.128   

# ssh slave.localdomain #如果需要主机名登陆,也需要提前登陆一下,因为第一次登陆需要输入yes


4、登陆本机也不需要密码


# ssh-copy-id  -i ~/.ssh/id_rsa.pub 192.168.75.130

# ssh 192.168.75.130

# ssh mater.localdomain



二、192.168.75.128 上做同样的操作

1、在~/.ssh目录下产生公钥与私钥对.

# 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:

e4:bb:24:9c:f9:01:a8:80:4d:db:66:5b:47:48:c5:ca [email protected]

The key's randomart image is:

+--[ RSA 2048]----+

|      .o.        |

|     . ..        |

|  .  ...o        |

|.o o .E+         |

|o o = o S        |

| . + + = .       |

|  . . = +        |

|       + o       |

|        o        |

+-----------------+


2、ssh-copy-id 将公钥id_rsa.pub的内容追加到远程机器的 ~/ .ssh/authorized_key.文件中

# ssh-copy-id  -i ~/.ssh/id_rsa.pub 192.168.75.130 

[email protected]'s password: 

Now try logging into the machine, with "ssh '192.168.75.130'", and check in:


  .ssh/authorized_keys


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


3、登录到远程机器不用输入密码,登陆之后会将对方的信息,记录在known_hosts文件中,第一次登陆需要输入yes

# ssh 192.168.75.130  

# ssh master.localdomain #如果需要主机名登陆,也需要提前登陆一下,因为第一次登陆需要输入yes


4、登陆本机也不需要密码,如果有登陆主机名,


# ssh-copy-id  -i ~/.ssh/id_rsa.pub 192.168.75.128

# ssh 192.168.75.128

# ssh slave.localdomain 


参考:http://blog.chinaunix.net/uid-26284395-id-2949145.html


本文出自 “小鱼的博客” 博客,转载请与作者联系!

你可能感兴趣的:(linux,ssh,双机互信)