sudo within ssh remote

hoyanet

New Member
Joined
Jul 23, 2018
Messages
1
Reaction score
0
Credits
0
Hi .

I have a problem, please see if anyone can help me out:

I have 2 servers which I have connected through an ssh without password (with public keys permissions, etc). The user input both on the client and on the server is john.

That is, I do:

ssh john @ server uname -a for example (and I have managed to work without password) (on the server there is also the user john as I said)

But now I need to do

The normal operation in the server is to do (entering with user john) then sudo su - userserver2 and then execute a script with sudo (since it is root) with sudo /etc/init.d/scritp1

What I want is to be able to execute the script from the remote client

but ssh john @ server "sudo su - userserver2" for example, it does not work, it gives me permission denied.

How could I do it please?

Thanks in advance.
 


Greetings hoyanet,
first of all welcome to Linux.org .
First off all which server distribution do you use?
Is John in the sudoer file?

instead of direct call the sudo su via ssh try to call it through an bash with option -s and an pipe.
Example:
ssh max @ server1 /usr/bin/bash -s | echo "Hello Wordl!"

Greetings

Scoobithepirate
 

Staff online


Top