有没有办法在 中使用多个命令sshpass,我尝试了不同的组合,但它会引发错误。
$ sudo sshpass -p $password ssh -t -oStrictHostKeyChecking=no $username@$ipaddress << EOF
command_one
command_two
command_three
EOF
Run Code Online (Sandbox Code Playgroud)
什么是正确和准确的命令,如果可能,请给我一个例子。
#!/bin/bash
while IFS="," read -r f1 f2
do
username="testuser"
SSHPASS='abcde' sshpass -e ssh -t "$username@$f1" "sudo su - root -c 'yum -y install wget'"< /dev/null ;
done < Input.txt
Run Code Online (Sandbox Code Playgroud)
现在我不仅想wget安装,还想执行一个脚本。
例如:Grep 并检查服务是否正在运行,删除不需要的文件夹等。
我已经尝试过:
#!/bin/bash
while IFS="," read -r f1 f2
do
username="testuser"
SSHPASS='abcde' sshpass -e ssh -t "$username@$f1" "sudo su - root -c
if [ -d /opt/xxxx ]; then
rm -rf /opt/xxxx
if [ -d /etc/xxxx ]; then
rm -rf /etc/xxxx
fi"< /dev/null ;
done < Input.txt
Run Code Online (Sandbox Code Playgroud)
看来不行。我如何传递一个脚本以在远程计算机上以 …
当我在 alpine linux 上安装 sshpass 时,它将安装并且如果您不带参数运行它,文档将显示,但使用任何参数(有效或无效)返回sshpass: Failed to run command: No such file or directory.
它是路径化的,即使使用绝对路径,它也具有相同的行为。我想将它与 ansible 一起使用,但它甚至不能直接工作。
我似乎无法在网上找到有关此功能或不适用于其他人的任何信息,但我使用了其他人的容器和我自己的容器,但我无法让它在任何一个上运行。 https://pkgs.alpinelinux.org/package/v3.3/main/x86/sshpass
$ docker run -it --rm williamyeh/ansible:alpine3 ash
/ # 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 …Run Code Online (Sandbox Code Playgroud) 我为 SSH 连接配置了密钥对。它可以工作,但当然需要密码。
ssh user1@10.7.175.143
Run Code Online (Sandbox Code Playgroud)
所以现在我尝试使用我安装的 sshpass 登录。我尝试过使用-p财产,但也尝试过使用-f财产,但没有任何效果 - 它只是挂起。
verbose 在客户端提供这些信息
sshpass -v -p "pass" ssh user1@10.7.175.143
SSHPASS searching for password prompt using match "assword"
SSHPASS read:
SSHPASS read: Enter passphrase for key '/home/user1/.ssh/id_rsa':
Run Code Online (Sandbox Code Playgroud)
在服务器端我可以在日志中看到这些信息:
Accepted key RSA SHA256:V/V29pA2Ps5k/lBgz2R5XFP6vaaaOUN5hj0hca+j8TI found at __PROGRAMDATA__/ssh/administrators_authoriz
ed_keys:1
debug3: mm_answer_keyallowed: publickey authentication test: RSA key is allowed
debug3: mm_request_send: entering, type 23
debug3: send packet: type 60 [preauth]
debug2: userauth_pubkey: authenticated 0 pkalg rsa-sha2-256 [preauth]
debug3: user_specific_delay: user specific delay …Run Code Online (Sandbox Code Playgroud)