使用scp在linux主机之间无密码复制文件/目录
2010-02-21 20:58
866 查看
当两台LINUX主机之间要互传文件时可使用SCP命令来实现,建立信任关系之后可不输入密码。
把你的本地主机用户的ssh公匙文件复制到远程主机用户的~/.ssh/authorized_keys文件中
假设本地主机linux100,远程主机linux200
一,在linux100主机里的用户
运行
#ssh-keygen -t rsa
结果如下
QUOTE:
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
二,把linux100主机上的id_rsa.pub文件拷贝到linux200主机的root用户主目录下的.ssh目录下,并且改名为authorized_keys
即:
/root/.ssh/authorized_keys
这样在linux100主机上使用scp命令复制文件到linux200上将不提示输入密码了,直接复制了。
反之亦然!
三,复制文件或目录命令:
复制文件:
(1)将本地文件拷贝到远程
scp 文件名 --用户名@计算机IP或者计算机名称:远程路径
(2)从远程将文件拷回本地
scp --用户名@计算机IP或者计算机名称:文件名 本地路径
复制目录:
(1)将本地目录拷贝到远程
scp -r 目录名 用户名@计算机IP或者计算机名称:远程路径
(2)从远程将目录拷回本地
scp -r 用户名@计算机IP或者计算机名称:目录名本地路径
----------------------------------------------------------------------------------------------------------------------------------------------
把你的本地主机用户的ssh公匙文件写入到远程主机用户的~/.ssh/authorized_keys文件中,具体方法
假设本地主机localhost,远程主机remote
一,在localhost主机里的用户
运行 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文件拷贝到remote主机的用户目录下
cat id_rsa.pub >~/.ssh/authorized_keys
就可以了
这样localhost主机的用户就可以通过ssh而不用密码登陆remote主机
在测试当中发现经常出现以下错误:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
1f:a3:2b:b5:27:0c:5c:7b:89:27:ff:ab:cd:ba:31:66.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:6
RSA host key for 60.28.15.234 has changed and you have requested strict checking.
Host key verification failed.
解决办法是把known_hosts文件删掉就可以了
--------------------------------------------------------------
把你的本地主机用户的ssh公匙文件复制到远程主机用户的~/.ssh/authorized_keys文件中
假设本地主机linux100,远程主机linux200
一,在linux100主机里的用户
运行
#ssh-keygen -t rsa
结果如下
QUOTE:
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
二,把linux100主机上的id_rsa.pub文件拷贝到linux200主机的root用户主目录下的.ssh目录下,并且改名为authorized_keys
即:
/root/.ssh/authorized_keys
这样在linux100主机上使用scp命令复制文件到linux200上将不提示输入密码了,直接复制了。
反之亦然!
三,复制文件或目录命令:
复制文件:
(1)将本地文件拷贝到远程
scp 文件名 --用户名@计算机IP或者计算机名称:远程路径
(2)从远程将文件拷回本地
scp --用户名@计算机IP或者计算机名称:文件名 本地路径
复制目录:
(1)将本地目录拷贝到远程
scp -r 目录名 用户名@计算机IP或者计算机名称:远程路径
(2)从远程将目录拷回本地
scp -r 用户名@计算机IP或者计算机名称:目录名本地路径
----------------------------------------------------------------------------------------------------------------------------------------------
把你的本地主机用户的ssh公匙文件写入到远程主机用户的~/.ssh/authorized_keys文件中,具体方法
假设本地主机localhost,远程主机remote
一,在localhost主机里的用户
运行 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文件拷贝到remote主机的用户目录下
cat id_rsa.pub >~/.ssh/authorized_keys
就可以了
这样localhost主机的用户就可以通过ssh而不用密码登陆remote主机
在测试当中发现经常出现以下错误:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
1f:a3:2b:b5:27:0c:5c:7b:89:27:ff:ab:cd:ba:31:66.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:6
RSA host key for 60.28.15.234 has changed and you have requested strict checking.
Host key verification failed.
解决办法是把known_hosts文件删掉就可以了
--------------------------------------------------------------
相关文章推荐
- scp在Linux主机之间复制文件/目录不用输入密码
- 使用scp在linux主机之间复制文件目录
- 当两台LINUX主机之间要互传文件时可使用SCP命令来实现
- 当两台LINUX主机之间要互传文件时可使用SCP命令来实现
- linux 的 scp 命令 可以 在 linux 之间复制 文件 和 目录;
- 【Linux命令】用 scp 命令在不同主机之间拷贝文件或目录
- linux 的 scp 命令 可以 在 linux 之间复制 文件 和 目录
- 使用scp在Linix之间复制文件或目录
- 使用scp在linux主机之间传输文件
- scp在Linux主机之间复制不需要密码
- linux 的 scp 命令 可以 在 linux 之间复制 文件 和 目录
- scp在Linux主机之间复制不用输入密码
- linux scp 无密码复制文件和目录
- 当两台LINUX主机之间要互传文件时可使用SCP命令来实现
- Linux机器之间复制文件和目录方式&Linux的scp命令详解
- scp在Linux主机之间复制不用输入密码
- 当两台LINUX主机之间要互传文件时可使用SCP命令来实现
- scp在Linux主机之间复制不用输入密码
- 使用scp在linux主机之间传输文件