shell icon indicating copy to clipboard operation
shell copied to clipboard

SSH expect

Open LianelLars opened this issue 2 years ago • 2 comments

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? :)

LianelLars avatar Aug 08 '23 14:08 LianelLars

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).

Vindaar avatar Aug 09 '23 08:08 Vindaar

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.

RokkuCode avatar Oct 13 '23 01:10 RokkuCode