Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392116
  • 博文数量: 103
  • 博客积分: 3073
  • 博客等级: 中校
  • 技术积分: 1078
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-23 15:04
文章分类

全部博文(103)

文章存档

2012年(13)

2011年(76)

2010年(14)

分类: LINUX

2011-09-26 17:22:46

1. The use of 'echo' and piping to the ftp process. Examples included:

使用echo 和管道(不推荐)。
  1. [myname@Firestream ~]$ echo "open romoteip
  2. user myname  mypassword
  3. verbose
  4. type binary
  5. put myfile
  6. quit" | ftp -in
2. 参数形式
  1. ************************************
  2. !/bin/sh
  3. #
  4. #Need the following entry in ~/.ftprc file to run this script:
  5. #
  6. # machine <anonymous ftp site> login ftp password <yourlogin>@yourdomain
  7. #
  8. if [ $# -le 0 ]; then
  9.         echo "Usage: get_ftp_file "
  10.         exit 1
  11. fi
  12. #
  13. # Go and get
  14. #
  15. file="$1"

  16. #
  17. # Replace /tmp with a directory name where you want to put your ftp file
  18. #
  19. cd /tmp
  20. echo "
  21. get $file
  22. quit" | ftp -i <ftp site>

  23. **************************************
  24. $ echo "user username passwd\n binary\n put sourcefile destfile\n" | ftp -n
  25. host

  26. **************************************
3.脚本(这种最好用)
  1. #!/bin/sh
  2. #
  3. # sample automatic ftp script to dump a file
  4. ftp -v -n $host << EOF
  5. user $login_name $password
  6. prompt
  7. cd $dir
  8. put $file
  9. quit
  10. EOF
chmod a+x b.bat
./b.bat

4  scp
 scp test  user@romoteip:
但是需每次输入密码,批处理,使用公钥密码传输。
假设A machine 和 B machine进行传输
<1>在Amachine 上 产生密码 
      ssh-keygen -t rsa
 
 <2>.ssh/id_rsa.pub 拷贝到 B机器上的相同位置(.ssh/),并改名为authorized_keys

<3 >测试一下
   scp  -p  Amachinefile  user@machineB:
   这里就不需要密码了。

5. 如果是多台呢,authorized_keys会不会覆盖掉?这里就讲怎么处理多台机器相互传输。
  多台机器的公钥密码
  方法1>使用 ssh-copy-id 来追加公钥。
     ssh-copy-id : install your identity.pub in a remote machine’s authorized_keys
      SYNOPSIS:  ssh-copy-id [-i [identity_file]] [user@]machine
ssh-copy-id默认端口是22,可能会碰到两个机器端口不一致问题,可以这样解决
ssh-copy-id -i ~/.ssh/id_rsa.pub “-p 10022 ”

---------------------------------------------------------------
exp: A 想与B建立公钥连接,且A不想输入密码。

1,在A上生成 rsa 公钥与私钥(ssh-keygen,3个回车默认情况),并把a的公钥传给B
2. 在B机器上,加入a的公钥
   方法: ssh-copy-id -i  a.pub  machineBuser@Bip
  不要搞反了。
  检查B机器上会出现 .ssh/authorized_keys 会出现A机器的rsa 公钥信息。
  这样从A登陆B就不需要密码了。

或者更简单的方法: 直接把B的public key 考入 A 的.authorized_keys 。
 
6使用expect
   现在还没时间学习,十一时学习,待补充
   
/**********************/
$ sftp user@remoteip
The authenticity of host 'remoteip (remoteip)' can't be established.
RSA key fingerprint is dxx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'remoteip' (RSA) to the list of known hosts.
user@remoteip 's password:
Connected to remoteip.
第一次执行sftp 时,会把 远程服务器的rsa 公钥加入本地的.ssh/authorized_keys 里面。


  
post:
爱死 RSA了,结束了记忆密码时代,又安全。

阅读(1246) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

2011-10-08 22:44:32