The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > Security
.
google unix.com



Security Discuss UNIX and Linux computer and network security, cybersecurity, cyberattacks, IT security, CISSP, OWASP and more.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
As root , running script as different user with su - problem dbsupp Shell Programming and Scripting 4 12-18-2008 01:28 AM
running X-11 programs as root Allasso UNIX for Advanced & Expert Users 8 12-28-2007 03:22 PM
Running out of Space (Root) scorpiyanz UNIX for Advanced & Expert Users 0 08-19-2005 10:22 AM
Running a command or script as root rm-r Shell Programming and Scripting 3 05-27-2005 08:58 AM
running a scr in rc3.d not as root, can i? kymberm UNIX for Advanced & Expert Users 6 11-12-2002 11:50 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-30-2009
irinotecan irinotecan is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 7
Running script through SSH as root

Hi all,

I have a situation where I have a shell script that I need to run remotely on multiple *nix machines via SSH. Unfortunately, some of the commands in it require root access. I know that best practices for ssh entail configuring it so that the root account cannot log in, you need to elevate to root via su after logging in with a regular account.

Unfortunately, this seems to leave me in a dilemma: How in a script can I elevate to root, since it will prompt me for a password that I will not be there to enter? Or, is there some other alternative from an advanced security perspective that will allow me to log in with an account that has root level access to the machine (but isn't the actual "root" account)?

Finally, just to head this off: No, I cannot set the script up in crontab to run as root at a certain time/frequency. The requirements for this script to run is: 1) SCP it to /var/tmp; 2) Execute via SSH as root or root-equivalent; 3) scrape the output; 4) Execute "rm /var/tmp/script.sh" via SSH to remove it.

Any suggestions?
  #2 (permalink)  
Old 03-30-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Are the privs required related to file access?

Try adding an account that can newgrp to the root, bin, adm, mail or whatever group it requires to get into the files in question.

Code:
newgrp root
  #3 (permalink)  
Old 03-30-2009
irinotecan irinotecan is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 7
Unfortunately I already tried this, and at least with one utility (ioscan on HP-UX), adding the group the utility was in did not help, and adding the group assigned to the block device it was trying to read from also did nothing. In fact, documentation I found for ioscan stated it had to be run as root. (I realize this is getting HP-UX specific at this point, but I know I had this problem with some Linux commands as well -- I believe that lshal can only be run as root per it's documentation)

Last edited by irinotecan; 03-30-2009 at 04:23 PM..
  #4 (permalink)  
Old 03-30-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
You are probably stuck with having to do this manually, if you don't want to compromise security.

One other poor choice - write a daemon - one that runs as root. Write the temp script to a protected directory via scp. Have the daemon run the script when it sees it out there, delete it, then email the output to you.

Can you push back on the limitations - like no crontab? You can always explain to mgt that you may be out days when this has to run. The reason I say this - it sounds like an arbitrary decision somewhere upstream.

Last edited by jim mcnamara; 03-30-2009 at 04:40 PM..
  #5 (permalink)  
Old 03-30-2009
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 205
Another compromise could be to create a new user with no password (but a valid shell and home directory), and use sudo to run the commands that need to be run as root. The user will have to be added to the /etc/sudoers file (using visudo or editsudo) and fine grain control can be used here to limit the commands that need to be run.
Then you will need to set up ssh keys for the user running the admin script and the new users you have created, so that they can ssh in without a password prompt.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0