红联Linux门户
Linux帮助

UNIX平台下远程拷贝文件的方法--SCP

发布时间:2006-11-26 00:35:54来源:红联作者:pkncoin
拥有多台服务器或测试的朋友也许常常会遇到在不同机器之间拷贝文件的情况,通常的做法通过FTP传输,当然也可以通过HTTP,SAMBA等,但这些都有一个通病,即每次必须输入密码或经过复杂的配置,很不方便.
下面我介绍一种安全又快速的远程复制文件的方法供大家参考:
1.命令:SCP --secure copy (remote file copy program)
些命令是openssh-clients附带的,机器之间传输完全是加密的
2.配置方法:
1)保证安装了SSH,最好是SSH2比较好
2)开启SSH证书认证
即,在配置文件(/etc/ssh/sshd_config)里,设定
RSAAuthentication yes
PubkeyAuthentication yes
3)生成并分发密钥对
$ ssh-keygen -d
屏幕提示:
Generating public/private dsa key pair.
Enter file in which to save the key (/home/mms/.ssh/id_dsa):
# 按回车保存为: /home/mms/.ssh/id_dsa,即当前用户mms的私钥
Enter passphrase (empty for no passphrase):
# 按回车,表示读取密钥时不需要密钥的密码
Enter same passphrase again:
# 确认密钥的密码,必须和上面的输入相同
Your identification has been saved in /home/mms/.ssh/id_dsa.
# 私钥保存信息
Your public key has been saved in /home/mms/.ssh/id_dsa.pub.
# 公钥保存信息
The key fingerprint is:
# 密钥指纹
分发公钥
为了使用密钥,必须将公钥分发到所要登录的远程服务器上.
copy id_dsa.pub到remote_host:/home/[user]/.ssh/
这里[user]为sftp使用的登录用户.若目录/home/[user]/.ssh/不存在,请先创建之.
b).将copy来的公钥文件改名为authorized_keys,如果已经存在authorized_keys,可以使用命令: cat id_dsa.pub >> authorized_keys 将其内容附加到authorized_keys的末尾
c).修改公钥文件的访问权限
chmod 644 authorized_keys
d)重启SSH服务
3.示例
scp test.txt root@192.168.6.90:/tmp
以上命令会将本地文件test.txt拷贝到远程机器192.168.6.90的/tmp目录下.
文章评论

共有 2341 条评论

  1. 69.147.76.* 于 2007-09-04 01:22:54发表:

    chocolate cake

  2. 72.51.37.* 于 2007-09-03 19:36:43发表:

    chocolate

  3. 210.42.140.* 于 2007-09-01 11:34:19发表:

    wmjon wmjon

  4. 210.42.140.* 于 2007-09-01 11:34:15发表:

    wmjon wmjon

  5. 195.225.177.* 于 2007-09-01 10:30:01发表:

    Great sie url:http://www.linuxdiyf.com/viewarticle.php?id=28161(1214171319):)

    name:Medved
    url:http://google.com
    email:none@none.com
    message:Great sie

  6. 195.225.177.* 于 2007-09-01 06:30:53发表:

    Great sie url:http://www.linuxdiyf.com/viewarticle.php?id=28161(1214171319):)

    name:Medved
    url:http://google.com
    email:none@none.com
    message:Great sie

  7. 195.225.177.* 于 2007-09-01 02:16:27发表:

    Great sie url:http://www.linuxdiyf.com/viewarticle.php?id=28161(1214171319):)

    name:Medved
    url:http://google.com
    email:none@none.com
    message:Great sie

  8. 195.225.177.* 于 2007-08-31 21:57:25发表:

    Great sie url:http://www.linuxdiyf.com/viewarticle.php?id=28161(1214171319):)

    name:Medved
    url:http://google.com
    email:none@none.com
    message:Great sie

  9. 195.225.177.* 于 2007-08-31 17:35:35发表:

    Great sie url:http://www.linuxdiyf.com/viewarticle.php?id=28161(1214171319):)

    name:Medved
    url:http://google.com
    email:none@none.com
    message:Great sie

  10. 195.101.183.* 于 2007-08-27 08:45:34发表:

    new jersey

  11. 193.191.168.* 于 2007-08-27 03:07:08发表:

    duplantis ministry

  12. 219.141.223.* 于 2007-08-27 01:44:22发表:

    studio max

  13. 195.225.177.* 于 2007-08-26 08:26:43发表:

    Great sie

  14. 192.72.124.* 于 2007-08-26 05:03:32发表:

    chili recipie

  15. 81.88.210.* 于 2007-08-26 05:01:04发表:

    pinhole camras

  16. 216.244.231.* 于 2007-08-25 01:35:14发表:

    gibbon leeza

  17. 192.72.124.* 于 2007-08-25 00:07:45发表:

    yuor dirty mind

  18. 125.46.36.* 于 2007-08-24 00:40:05发表:

    simile peoms