Skip to content
Advertisement

change user and run ssh instruction in 1 line

I’m trying to change my user to one that doesn’t need password to run ssh instructions and then do exactly that, run an ssh instruction. What I have now is:

JavaScript

But I’m getting the answer:

JavaScript

if I put the instructions in a different file called testit like this:

JavaScript

and I run:

JavaScript

it works!, but I need to use the one line instruction, someone know what should I change to make it work?

Advertisement

Answer

JavaScript

why don’t you use just sudo -u testUser as it is supposed to be used?

But anyway, manual pages for the tools you are using is a good start. For sudo:

JavaScript

This looks good and fits into your example.

For su:

JavaScript

Ola … su does not have any argument command, unless you provide also -c switch, which is written also in the manual page. And it is [option], so it should come in front of [username]! Something like this should do the job:

JavaScript

but as I already mentioned, it can be significantly simplified by using sudo only:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement