sshpass-Linux命令之非交互SSH密码验证
sshpass-Linux命令之非交互SSH密码验证
参考网址:https://www.cnblogs.com/chenlaichao/p/7727554.html
ssh登陆不能在命令行中指定密码。sshpass的出现,解决了这一问题。sshpass用于非交互SSH的密码验证,一般用在sh脚本中,无须再次输入密码。
它允许你用 -p 参数指定明文密码,然后直接登录远程服务器,它支持密码从命令行、文件、环境变量中读取。
其默认没有安装,需要手动安装,方法如下:
1 | 下载网址:https: //sourceforge .net /projects/sshpass/files/ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | [root@db130 ~] # ll /root/sshpass-1.06.tar.gz -rw-r--r-- 1 root root 112205 Mar 25 15:45 /root/sshpass-1 .06. tar .gz [root@db130 ~] # tar -zxf sshpass-1.06.tar.gz [root@db130 ~] # cd sshpass-1.06 [root@db130 sshpass-1.06] # ./configure --prefix=/usr/local/sshpass/ [root@db130 sshpass-1.06] # make [root@db130 sshpass-1.06] # make install [root@db130 sshpass-1.06] # cp /usr/local/sshpass/bin/sshpass /usr/bin/ # 出现如下,表明安装成功 [root@db130 sshpass-1.06] # 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 [root@db130 sshpass-1.06] # # 用法简介: -p password # 后接密码 [root@db130 ~] # sshpass -p '12345678' ssh root@192.168.142.128 'ifconfig eth0' eth0 Link encap:Ethernet HWaddr 00:0C:29:B0:62:1B inet addr:192.168.142.128 Bcast:192.168.142.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feb0:621b /64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5915 errors:0 dropped:0 overruns:0 frame:0 TX packets:533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:407552 (398.0 KiB) TX bytes:111865 (109.2 KiB) [root@db130 ~] # -f filename #后跟保存密码的文件名,密码是文件内容的第一行。 [root@db130 ~] # cat 1.txt 12345678 [root@db130 ~] # sshpass -f 1.txt ssh root@192.168.142.128 Last login: Mon Mar 25 22:36:05 2019 from 192.168.142.1 [root@xbj128 ~] # exit logout Connection to 192.168.142.128 closed. -e #将环境变量SSHPASS作为密码,是临时的 [root@db130 ~] # -e #将环境变量SSHPASS作为密码^C [root@db130 ~] # export SSHPASS=12345678 [root@db130 ~] # sshpass -e ssh root@192.168.142.128 "ifconfig eth0" eth0 Link encap:Ethernet HWaddr 00:0C:29:B0:62:1B inet addr:192.168.142.128 Bcast:192.168.142.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feb0:621b /64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6027 errors:0 dropped:0 overruns:0 frame:0 TX packets:588 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:419116 (409.2 KiB) TX bytes:121683 (118.8 KiB) # 传出本地文件到远程 [root@db130 ~] # sshpass -f 1.txt scp /root/sshpass-1.06.tar.gz root@192.168.142.128:/root/ # 拉取远程文件到本地 [root@db130 ~] # sshpass -f 1.txt scp root@192.168.142.128:/root/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz /tmp/ |
分类:
Linux
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
2018-03-25 python 购物车小程序