how to launch linux subshell for SSH_ASKPASS to wo

2019-04-15 12:32发布

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 contains just the password

When I execute the script, it asks for the password.

Thanks in Adv.

标签: linux ssh
2条回答
何必那么认真
2楼-- · 2019-04-15 12:40

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
查看更多
放我归山
3楼-- · 2019-04-15 12:46

I've been looking for this as well ;)) This seems to be the solution

Bash (Works 100%)

http://andre.frimberger.de/index.php/linux/reading-ssh-password-from-stdin-the-openssh-5-6p1-compatible-way/

Or using Expect

http://bash.cyberciti.biz/security/expect-ssh-login-script/

PS: I know this is a late answer, but probably will help someone else :)

查看更多
登录 后发表回答