sshpass之非交互SSH密码验证

    SSH登陆不能在命令行中指定密码。sshpass用于非交互SSH的密码验证,一般用在shell脚本中,无须手动输入密码。它允许你用 -p 参数指定明文密码,然后直接登录远程服务器,它支持密码从命令行、文件、环境变量中读取。


一、安装sshpass:

1. 通过源码编译安装

1
2
3
4
# http://sourceforge.net/projects/sshpass/ 下载地址
$ tar  - zxvf sshpass - xx.tar.gz
$ . / configure
$ make && make install

2. 通过源服务器安装

1
$ sudo apt - get install sshpass


二、使用sshpass

1. 登录远程服务器

1
$ sshpass  - p password ssh username@ip_addr

2. scp上传或下载文件

1
2
$ sshpass  - p password scp username@ip_addr: / remote_dir  / local_dir
$ sshpass  - p password scp  / local_dir username@ip_addr: / remote_dir

3. sshpass命令详细用法

1
2
3
4
5
6
7
8
9
10
11
12
Usage: sshpass [ - f| - d| - p| - e] [ - hV] command parameters
    - f filename   Take password to use  from  file
    - d number     Use number as  file  descriptor  for  getting password
    - p password   Provide password as argument (security unwise)
    - e            Password  is  passed as env - var  "SSHPASS"
    With no parameters  -  password will be taken  from  stdin
 
    - P prompt     Which string should sshpass search  for  to detect a password prompt
    - v            Be verbose about what you're doing
    - h            Show  help  (this screen)
    - V             Print  version information
At most one of  - f,  - d,  - or  - e should be used

本文转自戴柏阳的博客博客51CTO博客,原文链接http://blog.51cto.com/daibaiyang119/2045464如需转载请自行联系原作者

daibaiyang119
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值