lb5645284 发表于 2018-5-21 08:24:00

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 root@slave0.localdomain.com
  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
  root@192.168.75.128'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 root@slave0.localdomain.com
  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
  root@192.168.75.130'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
  
页: [1]
查看完整版本: Linux 双机互信