shell
shell copied to clipboard
SSH expect
If i do:
#main_file.nim
import shell
shell:
"ssh [email protected] whoami"
expect: "password:"
send:"my_password"
nothing happend. But if i do:
#first_file.nim
import shell
shell:
./second_file
expect: "something"
send:"i send info"
#second_file:
echo "Enter something"
let a: string = readLine(stdin)
echo "Entered: ", a
Everything works correctly. Soooo.... is it have to working like that? :)
The issue is that password input is handled differently in the terminal (not via stdin). I'm not sure if it's possible to catch that from a process and feed the password. Sounds kind of like a security nightmare. Maybe there is a way, but one would have to do some research.
For something like this you should really just use an SSH key and then use ssh-agent.
eval `ssh-agent`
ssh-add ~/.ssh/id_<my_ssh_key>
to avoid the password requirement. I haven't done this myself, so I'm not entirely sure about how to make sure the SSH agent is available in the subprocess that is started (I've only used ssh-agent in a contained terminal session).
alternatively: use the key directly with the ssh command:
ssh -i ~/.ssh/id_<my_ssh_key> [email protected] whoami
in my opinion using passwords with ssh should removed and key only auth should the only way to auth.