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
相关文章
|
5月前
|
网络安全 数据安全/隐私保护
ssh远程执行命令自动输入密码方式
ssh远程执行命令自动输入密码方式
521 0
|
6月前
|
运维 应用服务中间件 网络安全
Ansible自动化运维工具之解决SSH连接使用明文密码问题(4)
Ansible自动化运维工具之解决SSH连接使用明文密码问题(4)
|
1月前
|
安全 Shell 网络安全
ssh配置无密码验证
ssh配置无密码验证要在SSH中配置无密码验证,您需要使用公钥验证【2月更文挑战第18天】
39 1
|
2月前
|
安全 网络协议 Linux
|
2月前
|
安全 网络协议 Shell
SSH连接密码问题:原因、表现与解决方案
SSH连接密码问题:原因、表现与解决方案
91 3
|
2月前
|
关系型数据库 网络安全 数据库
通过SSH登录OceanBase数据库需要修改用户密码,然后使用SSH客户端进行远程登录
通过SSH登录OceanBase数据库需要修改用户密码,然后使用SSH客户端进行远程登录
70 6
|
2月前
|
存储 Linux 网络安全
如何在 Linux 中删除 SSL 证书和 SSH 密码?
如何在 Linux 中删除 SSL 证书和 SSH 密码?
82 1
如何在 Linux 中删除 SSL 证书和 SSH 密码?
|
3月前
|
安全 Linux Shell
Linux服务器配置SSH免密码登录后,登录仍提示输入密码(一次真实的问题排查解决记录)
Linux服务器配置SSH免密码登录后,登录仍提示输入密码(一次真实的问题排查解决记录)
87 0
|
7月前
|
网络安全 开发工具 数据安全/隐私保护
GitHub不再支持密码验证解决方案:SSH免密与Token登录配置
今天提交代码,push到GitHub上,突然出现这个问题。 remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. fatal: unable to acce
|
8月前
|
安全 Ubuntu Linux
如何在 Linux 中设置 SSH 无密码登录
如何在 Linux 中设置 SSH 无密码登录
160 0