LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question about SSH (https://www.linuxquestions.org/questions/linux-newbie-8/question-about-ssh-745902/)

ac1115 08-07-2009 04:48 PM

Question about SSH
 
Hello,

I'm trying to make either a single command or a shell script that I can run that will SSH into another box, login as root, then execute a shell script on the remote box.

I've been trying to make one, however I've been unsuccessful so far. Any suggestions?


Much appreciated!

rjlee 08-07-2009 06:26 PM

If you just want to run a command as root (i.e. without logging in and running .bash_profile) then sudo's probably the easiest way:
Code:

ssh user@server.domain sudo command
I just tried that on my Ubuntu box, and it worked - although it did print the admin password the second time. You could always configure sudo to allow the user to run the specific command without a password.

You can't run su from the ssh command-line, because it needs a terminal of some sort. You could create a virtual terminal, then attach it to the standard input and output streams provided by sshd, but that's much more work than the sudo route.

Hope that helps,

—Robert J Lee

karamarisan 08-07-2009 06:45 PM

You could also setuid your script and run it as an unprivileged user. This avoids the security problem of allowing your account to gain root on that server without a password, but that means you need to be super careful about who can write to that script.


All times are GMT -5. The time now is 11:16 PM.