LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-29-2010, 11:10 AM   #1
deelinux
Member
 
Registered: Nov 2009
Posts: 35

Rep: Reputation: 15
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
 
Old 06-29-2010, 11:19 AM   #2
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,027

Rep: Reputation: 69
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.
 
Old 06-29-2010, 11:45 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by trist007 View Post
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.
 
Old 06-29-2010, 11:46 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,926

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by deelinux View Post
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.
 
Old 06-29-2010, 12:18 PM   #5
hanzerik
Member
 
Registered: Jan 2002
Location: Cheyenne Wyoming
Distribution: Debian/Raspbian/Mint
Posts: 717

Rep: Reputation: 32
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.
 
Old 06-29-2010, 12:52 PM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Determine the remote system in LAN running idle borganve Linux - Networking 1 10-09-2009 10:10 AM
Problem Running Remote X application on a 10.1 system kaplan71 SUSE / openSUSE 0 04-02-2009 11:57 AM
Problem running remote X applications on a Mac OS X 10.5.5 Intel system kaplan71 Other *NIX 1 10-07-2008 10:06 AM
running remote X applications via Putty from a Windows XP system John Sorkin Linux - Newbie 1 08-23-2008 11:19 PM
running shell command on remote machine with ssh qrshat Solaris / OpenSolaris 3 08-17-2006 08:32 AM


All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration