现在的位置: 首页 > 综合 > 正文

scp在Linux主机之间复制不用输入密码

2013年08月02日 ⁄ 综合 ⁄ 共 1099字 ⁄ 字号 评论关闭

 把你的本地主机用户的ssh公匙文件复制到远程主机用户的~/.ssh/authorized_keys文件中,假设本地主机linux(@192.168.30.1),远程主机linux(@192.168.30.2).

  一,在本地主机里的用户(可以是omapp, custadmin, root等任意准备使用scp的user)
  运行
  #ssh-keygen -t rsa
  结果如下
  Generating public/private rsa key pair.
  Enter file in which to save the key (/home/.username/ssh/id_rsa):#回车
  Enter passphrase (empty for no passphrase):#回车
  Enter same passphrase again:#回车
  Your identification has been saved in /home/.username /.ssh/id_rsa.
  Your public key has been saved in /home/.username /.ssh/id_rsa.pub.
  The key fingerprint is:
  38:25:c1:4d:5d:d3:89:bb:46:67:bf:52:af:c3:17:0c username@localhost
  Generating RSA keys:
  Key generation complete.
  会在用户目录~/.ssh/产生两个文件,id_rsa,id_rsa.pub

  二,把本地主机上生成的id_rsa.pub文件拷贝到远程主机的用户主目录下的.ssh目录下(可以是omapp, custadmin, root等任意准备使用scp的user),并且改名为authorized_keys
  即:
  /root/.ssh/authorized_keys (或者/home/omapp/.ssh/authorized_keys 等)
  这样在本地主机上使用scp命令复制文件到远程主机上将不提示输入密码了,直接复制了。反之亦然!

  三,复制文件或目录命令:
  复制文件:
  (1)将本地文件拷贝到远程
  scp 文件名 --user@192.168.30.2:远程路径
  (2)从远程将文件拷回本地
  scp --user@192.168.30.2:文件名 本地路径
  复制目录:
  (1)将本地目录拷贝到远程
  scp -r 目录名 --user@192.168.30.2:远程路径
  (2)从远程将目录拷回本地
  scp -r --user@192.168.30.2:目录名 本地路径

抱歉!评论已关闭.