ssh master - execute su remotely

Scony

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 ?

meuh

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Execute a sudo NOPASSWD command remotely via SSH

From Dev

Is it possible to execute commands remotely (ssh), through a Java program

From Dev

Execute script remotely over SSH and disconnect from running process

From Dev

How to execute 'su' command using parallel-ssh

From Dev

Not able to execute remotely placed ssh script with parameter using paramiko ssh client

From Dev

SSH into Ubuntu VM remotely

From Dev

remotely startx over ssh

From Dev

Execute a remote ssh command as root user supplying su password in command line

From Dev

Unable to execute tcpdump remotely with Paramiko

From Dev

gcloud compute execute command remotely

From Dev

execute su with additional commands

From Dev

echo pwd remotely via ssh

From Dev

process a file remotely using ssh

From Dev

Cannot connect remotely using ssh

From Dev

SSH : Remotely run a script and stay there

From Dev

Cannot connect remotely using ssh

From Dev

Change IP remotely over ssh

From Dev

SSH remotely into Bash on Ubuntu on Windows

From Dev

remotely executing a command using ssh

From Dev

Execute command if su to a certain user

From Dev

su cannot execute bin/bash/****

From Dev

EMR ssh on Master node

From Dev

Remotely execute a Spark job on an HDInsight cluster

From Dev

Execute commands on linux remotely through Dropbox ?

From Dev

How to execute multiple commands remotely on few servers?

From Dev

Unix Environment variable is not setting with execute remotely

From Dev

how to remotely execute a shell script with elevated privileges

From Dev

Remotely execute commands but still have control of the host

From Dev

Execute npm start remotely from 2 locations

Related Related

HotTag

Archive