Linux命令:sshpass
sshpass介绍
sshpass是一款凡是为凡是使用ssl方式访问的操作提供一个免输入密码的非交互式操作,以便于在脚本中执行ssl操作,如ssh,scp等。sshpass是一家以色列公司Lingnu开发的,由于软件还处于初期,bug还是很有可能出现的。所以使用这个软件时要慎重。
sshpass安装
源码安装
curl -O -L http://downloads.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz && tar xvzf sshpass-1.06.tar.gz && cd sshpass-1.06 && ./configure && make && sudo make install
自己安装软件包
rpm -ivh $BaseDir/tools/sshpass/sshpass-1.06-.el6.x86_64.rpm
自动安装软件包
# yum -y install sshpass
sshpass用法
sshpass [-ffilename|-dnum|-ppassword|-e] [options] command arguments
-p 直接在命令行给出密码
sshpass -p '123' ssh root@192.168.1.1 'ls -l'
-f 文件首行给出密码。
sshpass -f file.txt ssh root@192.168.1.1 'ls -l'
-e 由环境变量SSHPASS给出密码。
export SSHPASS='123'
sshpass -e ssh root@192.168.1.1 'ls -l'
-d 由文件描述符给出密码。
sshpass -d 51671 ssh root@192.168.1.1 'ls -l'
对于ssh的第一次登陆,会提示:“Are you sure you want to continue connecting (yes/no)”,这时用sshpass会不好使,可以在ssh命令后面加上 -o StrictHostKeyChecking=no来解决。比如说上面的命令,就可以写作ssh -p efghi scp abc@192.168.0.5:/home/xxx/test /root -o StrictHostKeyChecking=no。
sshpass帮助
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, -p or -e should be used
SSHPASS(1) Sshpass User Manual SSHPASS(1) NAME
sshpass - noninteractive ssh password provider SYNOPSIS
sshpass [-ffilename|-dnum|-ppassword|-e] [options] command arguments DESCRIPTION
This manual page documents the sshpass command. sshpass is a utility designed for running ssh using the mode referred to as "keyboard-interactive" password authentication, but in non-interactive mode. ssh uses direct TTY access to make sure that the password is indeed issued by an interactive keyboard user. Sshpass runs ssh in a dedicated tty, fooling it into thinking it is
getting the password from an interactive user. The command to run is specified after sshpass' own options. Typically it will be "ssh" with arguments, but it can just as well be any other command. The password prompt used by
ssh is, however, currently hardcoded into sshpass. Options
If no option is given, sshpass reads the password from the standard input. The user may give at most one alternative source for the password: -ppassword
The password is given on the command line. Please note the section titled "SECURITY CONSIDERATIONS". -ffilename
The password is the first line of the file filename. -dnumber
number is a file descriptor inherited by sshpass from the runner. The password is read from the open file descriptor. -e The password is taken from the environment variable "SSHPASS". -P Set the password prompt. Sshpass searched for this prompt in the program's output to the TTY as an indication when to send the password. By default sshpass looks for the
string "password:" (which matches both "Password:" and "password:"). If your client's prompt does not fall under either of these, you can override the default with this
option. -v Be verbose. sshpass will output to stderr information that should help debug cases where the connection hangs, seemingly for no good reason. SECURITY CONSIDERATIONS
First and foremost, users of sshpass should realize that ssh's insistance on only getting the password interactively is not without reason. It is close to impossible to
securely store the password, and users of sshpass should consider whether ssh's public key authentication provides the same end-user experience, while involving less hassle and
being more secure. The -p option should be considered the least secure of all of sshpass's options. All system users can see the password in the command line with a simple "ps" command. Sshpass
makes a minimal attempt to hide the password, but such attempts are doomed to create race conditions without actually solving the problem. Users of sshpass are encouraged to
use one of the other password passing techniques, which are all more secure. In particular, people writing programs that are meant to communicate the password programatically are encouraged to use an anonymous pipe and pass the pipe's reading end to
sshpass using the -d option. RETURN VALUES
As with any other program, sshpass returns 0 on success. In case of failure, the following return codes are used: 1 Invalid command line argument 2 Conflicting arguments given 3 General runtime error 4 Unrecognized response from ssh (parse error) 5 Invalid/incorrect password 6 Host public key is unknown. sshpass exits without confirming the new key. In addition, ssh might be complaining about a man in the middle attack. This complaint does not go to the tty. In other words, even with sshpass, the error message from ssh is
printed to standard error. In such a case ssh's return code is reported back. This is typically an unimaginative (and non-informative) "255" for all error cases. EXAMPLES
Run rsync over SSH using password authentication, passing the password on the command line: rsync --rsh='sshpass -p 12345 ssh -l test' host.example.com:path . To do the same from a bourne shell script in a marginally less exposed way: SSHPASS=12345 rsync --rsh='sshpass -e ssh -l test' host.example.com:path . BUGS
Sshpass is in its infancy at the moment. As such, bugs are highly possible. In particular, if the password is read from stdin (no password option at all), it is possible that
some of the input aimed to be passed to ssh will be read by sshpass and lost. Sshpass utilizes the pty(7) interface to control the TTY for ssh. This interface, at least on Linux, has a misfeature where if no slave file descriptors are open, the master
pty returns EIO. This is the normal behavior, except a slave pty may be born at any point by a program opening /dev/tty. This makes it impossible to reliably wait for events
without consuming 100% of the CPU. Over the various versions different approaches were attempted at solving this problem. Any given version of sshpass is released with the belief that it is working, but experi‐
ence has shown that these things do, occasionally, break. This happened with OpenSSH version 5.6. As of this writing, it is believed that sshpass is, again, working properly. Lingnu Open Source Consulting April 25, 2015 SSHPASS(1)
Linux命令:sshpass的更多相关文章
- 终端-Linux命令之非交互SSH密码验证-Sshpass
Sshpass是使用SSH所谓的"交互式键盘密码身份验证"以非交互方式执行密码身份验证的工具 通俗来说就是 使用ssh密码登录 是需要在连接时手动输入密码的,没办法明文连接,如下图 ...
- 批量执行(Linux命令,上传/下载文件)
前言: 每个公司的网络环境大都划分 办公网络.线上网络,之所以划分的主要原因是为了保证线上操作安全: 对于外部用户而言也只能访问线上网络的特定开放端口,那么是什么控制了用户访问线上网络的呢? 防火墙过 ...
- Linux实战教学笔记04:Linux命令基础
第四节:Linux命令基础 标签(空格分隔):Linux实战教学笔记 第1章 认识操作环境 root:当前登陆的用户名 @分隔符 chensiqi:主机名 -:当前路径位置 用户的提示符 1.1 Li ...
- 像黑客一样使用 Linux 命令行
前言 之前在博客园看到一篇介绍 IntelliJ IDEA 配置的文章,它里面用的是 gif 动态图片进行展示,我觉得很不错.所以在我今天以及以后的博文中,我也会尽量使用 gif 动图进行展示.制作 ...
- 11 个很少人知道但很有用的 Linux 命令
Linux命令行吸引了大多数Linux爱好者.一个正常的Linux用户一般掌握大约50-60个命令来处理每日的任务.Linux命令和它们的转换对于Linux用户.Shell脚本程序员和管理员来说是最有 ...
- Linux命令随笔
Linux命令总结 man ==命令帮助; help ==命令的帮助(bash的内置命令); ls ==list,查看目录列表; -ld:查看目录权限; -l:(long)长格式显示属性; -F:给不 ...
- linux命令在线手册
下面几个网址有一些 Linux命令的在线手册,而且还是中文的,还可以搜索.非常方便 Linux命令手册 Linux命令大全 Linux中文man在线手册 每日一linux命令
- 常用的一些linux命令
最近接触到一些linux环境部署的事情,下面分享一些最近使用的比较频繁的一些linux命令~ 1.一次性移动多个文件到一个文件夹里 mv 被移动文件名 -t 目标文件夹 如:mv a.txt b.t ...
- 测试或运维工作过程中最常用的几个linux命令?
大家在测试工作过程中,可能会遇到需要你去服务器修改一些配置文件,譬如说某个字段的值是1 则关联老版本,是0则关联新版本,这时候你可能就需要会下vi的命令操作:或者查看session设置的时长,可能需 ...
随机推荐
- Jmeter(六)Jmeter脚本包含要素及书写习惯
Jmeter有丰富的组件,逻辑控制器.配置原件.Sampler.定时器.前置处理器.后置处理器.断言.监听器:而编写脚本一定要养成个人习惯,让人看到Jmeter的脚本目录结构树能够一目了然:因此,首先 ...
- [UE4]修改枪支碰撞体
一.Simple Collision:显示简单碰撞体,Comlex Collision:显示复杂碰撞体 二.添加简单和复杂碰撞体 三.自动生成复杂精确的碰撞体
- 第11章 拾遗5:IPv6和IPv4共存技术(3)_NAT-PT技术【全书完】
6.4 NAT-PT (1)NAT-PT和NAT的差别 ①NAT-PT(附带协议转换的网络地址转换)技术秉承NAT技术的思想,但在原理方面大有不同. ②NAT-PT和NAT本质的区别在于应用场合的不同 ...
- Linux Kafka源码环境搭建
本文主要讲述的是如何搭建Kafka的源码环境,主要针对的Linux操作系统下IntelliJ IDEA编译器,其余操作系统或者IDE可以类推. 1.安装和配置JDK确认JDK版本至少为1.7,最好是1 ...
- Device supprts x86,armeabi-v7a,but APK only aupports armeabi;模拟机不能运行。
在真机可以运行,模拟机却不可以: 这个是模拟机: 修改: defaultConfig { ndk{ abiFilters "armeabi" } } 为: defaultConfi ...
- JVM总结-java对象的内存布局
在 Java 程序中,我们拥有多种新建对象的方式.除了最为常见的 new 语句之外,我们还可以通过反射机制.Object.clone 方法.反序列化以及 Unsafe.allocateInstance ...
- 【Eclipse】将Tab替换为空格
工作中由于TAB和空格的占位不一样,在比对代码的时候,总是对齐方式不正确. 所以,就网搜了下Tab替换空格的方式,还不错哦,记录下来. 操作如下: 1.点击 window->preference ...
- linux中ps命令
ps的参数 -C的使用 [root@centos7 ~]# ps -C nginx -o user,pid,comm USER PID COMMAND root 2697 nginx nginx 26 ...
- <转载> FreeNAS的安装和简单配置 http://freenas.cn/?p=342
前些日子在公司搭了一个模拟生产环境的平台.由于是测试环境,资源有限只能使用虚拟机实现,所以存储这块就想到了使用FreeNAS.很早以前玩儿过几次,当时是生产环境需要上存储设备,经过对比还是选择的更可靠 ...
- WebForm(Application,ViewState,Repeater的Command操作)
一.AppliCation: 1.存储在服务器端,占用服务器内存 2.生命周期:永久 3.所有人都可访问的共有对象,一般用作服务器缓存 4.赋值:Application["key" ...