0

I have a server S that I need to connect to.

I'm connecting to S as user asdf with control master and after that I perform some stuff:

ssh -N -f -M -o ControlPath=$SSHSOCKET ${USER}@${IP} -p ${PORT} -i id_rsa
ssh -to ControlPath=$SSHSOCKET ${USER}@${IP} -p ${PORT} "su -c whoami && hostname && exit"

It works as expected, but second line asks me for password.

I am trying such fix:

echo 'qwerty' | ssh -t -to ControlPath=$SSHSOCKET ${K3_USER}@${IP} -p ${PORT} "su -c whoami && hostname && exit"

but it gets even worse:

muxserver_accept_control: tcgetattr: Inappropriate ioctl for device
tcgetattr: Inappropriate ioctl for device
Password:

For me, it's mandatory to ssh as asdf first. I also can't make any other ssh control master connections. I also can't modify any config on the target machine.

I just need to switch to root via ssh somehow. Any ideas ?

2
  • cant you move the password into the remote command: ssh ... "echo 'qwerty' | su -c ..." Commented Aug 24, 2015 at 12:42
  • @meuh Then I got: su: must be run from a terminal Commented Aug 24, 2015 at 12:47

1 Answer 1

2

Traditionally, interactive password problems are solved by using the expect command which creates an intermediary pseudo-tty to talk to the process. Here's an alternative python version using the equivalent python-pexpect package. Create a python file run.py:

import sys,pexpect
(pw,cmd) = sys.argv[1:]
child = pexpect.spawn(cmd)
child.expect(r'(?i)Password:')
child.sendline(pw)
print child.read()

and run it with the password and command to run as parameters:

python run.py  'qwerty' 'ssh -t -o ControlPath=$SSHSOCKET ${K3_USER}@${IP} -p ${PORT} "su -c whoami && hostname"'
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.