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 ?
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"'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments