问题描述
我正在尝试创建一个bash脚本,以使用SSH_ASKPASS和DISPLAY变量执行无密码的ssh命令.在我的bash脚本中,我在命令之前和之后添加了括号,以在新的子Shell中启动它.该脚本在新的shell中启动(获取新的PID),但仍附加了TTY.据我了解,要使SSH_ASKPASS正常工作,不应该附加TTY.请让我知道是否有人对此有解决方案.我只想用shell/bash脚本来做.
I am trying to create a bash script to execute a password-less ssh command with SSH_ASKPASS and DISPLAY variables. In my bash script, I have added parenthesis before and after the command to launch it in a new subshell. The script gets launched in a new shell(Gets a new PID) but TTY is still attached. From my understanding, for SSH_ASKPASS to work, TTY shouldn't be attached. Please let me know if anyone has a solution for this. I want to do it with shell/bash script only.
#!/bin/bash
SSH_ASKPASS=/tmp/abc
DISPLAY=localhost:0.0
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null 10.10.10.10 -lroot /bin/ls
/tmp/abc仅包含密码
/tmp/abc contains just the password
执行脚本时,它会要求输入密码.
When I execute the script, it asks for the password.
感谢Adv.
推荐答案
灵感来自强制ssh始终使用SSH_ASKPASS" :您需要分离终端.尝试使用setsid
:
Inspired from 'Force ssh to always use SSH_ASKPASS': you need to detach the terminal. Try with setsid
:
#!/bin/bash
SSH_ASKPASS=/tmp/abc
DISPLAY=localhost:0.0
setsid ssh -o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null 10.10.10.10 -lroot /bin/ls
这篇关于如何启动SSH_ASKPASS的Linux子外壳以在Linux中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!