sshpass 命令——ssh实现自动输入密码

tetsai
原创声明
本文由tetsai原创,转载请注明来源
连接ssh每次都要输入**,挺麻烦的
可以通过设置公钥(在被连接的主机上修改.ssh目录下的known_hosts,添加一行公钥就可以替代**)来实现免**连接
但如果一定要用**呢?有没有可以自动输入**的方法?
当时我试图使用echo 'password' | ssh [email protected]
结果不行,然后发现了一个叫sshpass的软件
只需要这一个命令
sshpass -p ** ssh [email protected]
就可以在连接时自动把**输入进去了,sshpass需要单独安装。
另外还可以指定文件
sshpass -f 存有**的文件.txt ssh [email protected]
以下是sshpass的help信息:
[@tetsai ~]$ 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