sshpass 绕过ssh 密码交互式验证
2018-07-03 00:59:38来源:博客园 阅读 ()
经常我们使用脚本登入服务器的时候,如果使用ssh 命令,经常会提示密码输入,我们不得不手动输入密码,因为ssh 没有 密码的选项。
为了能绕过交互式验证,我们使用sshpass命令解决这个问题:
1. 安装
? Desktop sudo yum install sshpass [sudo] password for xuyaowen: Last metadata expiration check: 0:04:22 ago on Mon 02 Jul 2018 11:25:32 AM CST. Package sshpass-1.06-5.fc28.x86_64 is already installed, skipping. Dependencies resolved. Nothing to do. Complete!
检查是否安装
[root@yaowenxu Desktop]# rpm -qa sshpass sshpass-1.06-5.fc28.x86_64
2. 查看 sshpass 命令帮助, 也可以使用 man sshpass
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.
[root@yaowenxu Desktop]# 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
3. 使用密码验证登录
? ~ sshpass -p 123 ssh root@10.66.65.15
4. ssh 第一次登录提示问题使用:
ssh -o StrictHostKeyChecking=no
来解决
? Desktop sshpass -p 123 ssh -o StrictHostKeyChecking=no root@10.66.8.142 Warning: Permanently added '10.66.8.142' (ECDSA) to the list of known hosts. Last login: Mon Jul 2 10:51:29 2018
5. 优缺点
优点: 快速,便捷
缺点: 密码明文暴露,可以使用 history 命令查找到
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:Linux 下解压 rar 文件
下一篇:Liunx常用命令
- SSH升级版本--8.2p1 2020-05-23
- Linux配置SSH免用户免密码登陆 2020-05-19
- centos 7 升级OpenSSH-8.2p1 2020-05-12
- Linux三阶段之五:SSH远程管理服务 2020-05-01
- ssh免密码登录 2020-04-22
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash