sshpass: 用于非交互的 ssh 密码验证

原贴:http://linuxtoy.org/archives/sshpass.html

sshpass: 用于非交互的 ssh 密码验证

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><script src="http://googleads.g.doubleclick.net/pagead/test_domain.js"></script><script>window.google_render_ad();</script> name="google_ads_frame" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-9432205671574187&dt=1231860579244&lmt=1231838298&output=html&slotname=9869120281&correlator=1231860579244&url=http%3A%2F%2Flinuxtoy.org%2Farchives%2Fsshpass.html&ea=0&ref=http%3A%2F%2Flinuxtoy.org%2F&frm=0&ga_vid=1487852779.1228736422&ga_sid=1231860458&ga_hid=1564599016&ga_fc=true&flash=0&u_h=800&u_w=1280&u_ah=800&u_aw=1280&u_cd=24&u_tz=480&u_his=2&u_nplug=1&u_nmime=1&dtd=17" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="250" scrolling="no" width="300">

[撰文/Zhang Huangbin (michaelbibby AT gmail.com)]

OpenSSH 自带的 ssh 客户端程序(也就是 ’ssh’ 命令)默认不允许你以非交互的方式传递密码,如:

ssh www.iredmail.org <<EOF
ssh_password
ls /var/
EOF

Shell 里这样的输入重定向使用得非常普遍,而且通常都工作得很好。但是 ssh 不允许这样的方式来传递密码,所以需要远程连上服务器后进行的批处理就无法进行。

sshpass 的出现,解决了这一问题。它允许你用 -p 参数指定明文密码,然后直接登录远程服务器。例如:

# sshpass -p 'ssh_password' ssh www.iredmail.org

用 ‘-p’ 指定了密码后,还需要在后面跟上标准的 ssh 连接命令。

用法就是这么简单。

注意:

我之前使用的 sshpass 是 1.0,在第一次连接服务器的时候,无法自动接受服务器的 Key 验证,也不会出现提示信息,所以第一次连接服务器请使用标准的 ssh 命令行客户端工具,接受了服务器的 key 之后再用 sshpass。

sshpass

署名 • 注明出处 • 非商业性使用

10 Comments

  1. 1 dybnu Commented @ 2009-01-13 10:25 amReply to this comment

    用ssh就不要用密码验证,openbsd的老大推荐

  2. 2 number5 Commented @ 2009-01-13 10:38 amReply to this comment

    为什么不直接用publickey验证?

  3. 3 hmy Commented @ 2009-01-13 10:47 amReply to this comment

    现实总不是理想的,哈哈,我刚接手管理的一些机器就是用ldap用户认证,不太方便放证书。
    所以我也是刚用上这个软件,挺不错的。

    另外有个软件也不错,叫
    sshproxy
    有兴趣的同学自己去看

  4. 4 hmy Commented @ 2009-01-13 10:48 amReply to this comment

    现在sshpass 支持 -f 选项,从文本文件读取密码,不用出现在命令行。

  5. 5 hmy Commented @ 2009-01-13 10:50 amReply to this comment

    晕,再补充一下,把
    StrictHostKeyChecking no
    加到/etc/ssh/ssh_config
    可以让ssh客户端自动接受新主机的host_key,不用每次都自己输入yes

  6. 6 bones7456 Commented @ 2009-01-13 12:06 pmReply to this comment

    我曾经也给ssh写过一个patch,加上password参数,提交上去,人家说不安全,想想也是,于是就用自己的sssh了.

  7. 7 walkerxk Commented @ 2009-01-13 2:06 pmReply to this comment

    为什么不直接用expect?

  8. 8 Mike Commented @ 2009-01-13 2:27 pmReply to this comment

    为啥不用key登陆?

  9. 9 gougo Commented @ 2009-01-13 2:29 pmReply to this comment

    感觉这东西的功能用expect就能够很简单的实现了 .

  10. 10 feiy Commented @ 2009-01-13 5:18 pmReply to this comment

    就是,为什么不用expect,我多台服务器需要批量进行命令操作都是用expect +ssh做的


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值