LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running a command on remote system . (https://www.linuxquestions.org/questions/linux-newbie-8/running-a-command-on-remote-system-816991/)

deelinux 06-29-2010 10:10 AM

Running a command on remote system .
 
Hello

I want to remote login as a non root user and then run a command under the root account.

I have set up the ssh/scp for the non root user and this configuration works fine.

What I dont know is how to run a command under root once remotly logged in as the non-root account.

I have to run this command under root, it cannot be changed.

If anyone knows how to do this or has any suggestions that would be great.

Systems are Redhat ES5 x64 2.6

Dee

trist007 06-29-2010 10:19 AM

Make sure 'PermitRootLogin' is enabled on the sshd_config on the server side. Then just su to become root and run the command. Or the alternative is to add that command to the sudoers file and sudo command.

unSpawn 06-29-2010 10:45 AM

Quote:

Originally Posted by trist007 (Post 4018327)
Make sure 'PermitRootLogin' is enabled on the sshd_config on the server side. Then just su to become root and run the command.

Using 'su' and the sshd_config "PermitRootLogin" directive are not related. Regardless you should never offer "PermitRootLogin Yes" as default answer unless the OP has ensured that this is a secured, trusted and isolated network and the OP understands the risks of doing things the non-SOP way.

TB0ne 06-29-2010 10:46 AM

Quote:

Originally Posted by deelinux (Post 4018322)
Hello

I want to remote login as a non root user and then run a command under the root account. I have set up the ssh/scp for the non root user and this configuration works fine.

What I dont know is how to run a command under root once remotly logged in as the non-root account. I have to run this command under root, it cannot be changed. If anyone knows how to do this or has any suggestions that would be great.

Systems are Redhat ES5 x64 2.6
Dee

You CAN allow remote root logins, but that's horribly unsafe. Better if you log in as a 'regular' user. Once there, you've got a couple ways to go:
  1. You can use 'expect' to script things, so the regular user just runs "su - root", then 'logs in', thereby putting them in as root, to run the script.
  2. You can (better), put the script on the remote box. Put the regular user into the SUDO'ers file, make sure it doesn't prompt for a password. Then, run it with "sudo -u root -s <script name>". Will then execute as root.

hanzerik 06-29-2010 11:18 AM

Is it a common reoccurring daily type command, or every once and a while just when needed type of thing?

If it needs to be done daily, weekly, monthly, hourly, etc, then setup a CRON job to do it. You won't even need to log on to the system.

schneidz 06-29-2010 11:52 AM

i do this everyday before i go to bed to shut off my htpc:
Code:

ssh xbmc@192.168.1.105 sudo shutdown -h now


All times are GMT -5. The time now is 04:40 AM.