centos 无密码 远程复制 scp

前言centos

为何有这个须要,因为服务器是负载均衡的,具备多个节点,因为如今是自动部署的,总不能在每一个节点上都部署一次吧?那若是在一台服务器上部署了,

直接远程复制到其他的服务器就比较方便了,可是因为scp是要输入密码的,使用脚本的话比较麻烦,因此就必须在两个机器之间创建相互信任的链接。就有

了这篇文章

准备服务器

虚拟机:192.168.0.201  做为A

      192.168.0.204  做为B
	  
系  统:centos 6.5 64 位

成  果:A无需密码SCP文件到B

开始负载均衡

一、用ssh登陆A,输入 ssh-keygen -b 4096 -t rsa  ,一直按回车就行。

   显示大概以下:
   
	Generating public/private rsa key pair.
	Enter file in which to save the key (/root/.ssh/id_rsa): 
	Created directory '/root/.ssh'.
	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:
	e5:81:a9:33:14:87:28:ae:37:4b:17:f3:e4:4a:4d:e1 root@waiyin1
	The key's randomart image is:
	+--[ RSA 2048]----+
	|     ....        |
	|  . . oo o       |
	| . . ...o o      |
	|  . o.E. o .     |
	| .   O+ S .      |
	|. + o +o         |
	| o = .           |
	|  . .            |
	|                 |
	+-----------------+

	执行完毕后,在目录 /root/.ssh/ 下会产生一对秘钥,其中`id_rsa.pub`是公钥,`id_rsa`是私钥;
	
	
二、把id_rsa.pub 复制到B服务器的./ssh目录下,并更名字为authorized_keys, 输入 :

  scp -p /root/.ssh/id_rsa.pub root@192.168.0.204:/root/.ssh/authorized_keys
  
  出现:
  
  root@192.168.0.204's password:        ---输入B服务器的密码
  scp: /root/.ssh/authorized_keys: No such file or directory,提示没有这个目录
  
  SSH进入**B服务器**运行:ssh-keygen -b 4096 -t rsa,而后再运行:scp -p /root/.ssh/id_rsa.pub root@192.168.0.204:/root/.ssh/authorized_keys
  
  root@192.168.0.204's password:  ---输入B服务器的密码
  id_rsa.pub  
  
  说明已经创建了联系,此时在A服务器 能够试用scp 不输入密码复制文件去B服务器!

总结dom

总结一下,若是想要A服务器 无密码远程服务制到服务器B 则须要把A生成的公钥放到B服务器,想要scp到C服务器也同样。
相关文章
相关标签/搜索