LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 10:10 AM   #1
deelinux
Member
 
Registered: Nov 2009
Posts: 39

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, 10:19 AM   #2
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 70
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, 10:45 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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, 10:46 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
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, 11:18 AM   #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, 11:52 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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



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 09:10 AM
Problem Running Remote X application on a 10.1 system kaplan71 SUSE / openSUSE 0 04-02-2009 10:57 AM
Problem running remote X applications on a Mac OS X 10.5.5 Intel system kaplan71 Other *NIX 1 10-07-2008 09:06 AM
running remote X applications via Putty from a Windows XP system John Sorkin Linux - Newbie 1 08-23-2008 10:19 PM
running shell command on remote machine with ssh qrshat Solaris / OpenSolaris 3 08-17-2006 07:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:52 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
Open Source Consulting | Domain Registration