Running script through SSH as root


 
Thread Tools Search this Thread
Special Forums Cybersecurity Running script through SSH as root
# 1  
Old 03-30-2009
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  
Old 03-30-2009
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  
Old 03-30-2009
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 05:23 PM..
# 4  
Old 03-30-2009
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 05:40 PM..
# 5  
Old 03-30-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with running a script via ssh

Hi, I'm trying to run a user defined shell script with options and arguments via ssh but getting error as ksh: Script.sh: not found. Here is what i'm running: ssh -t username@server 'cd /path/to/script; script.sh -t start here '-t' with script.sh, is an user defined option and 'start' is also... (3 Replies)
Discussion started by: xsam
3 Replies

2. UNIX for Dummies Questions & Answers

Script still running after ssh

I have the lines below on my script: script.ksh: case `hostname` in some_host) ssh server1A "/home/script.ksh $1 $2" ssh server1B "/home/script.ksh $1 $2" ssh server1C "/home/script.ksh $1 $2" ssh server1D "/home/script.ksh $1 $2" ssh... (1 Reply)
Discussion started by: erin00
1 Replies

3. Shell Programming and Scripting

Running a script as root but with different users inside

Hi All, my script.sh has the below lines, and i need to run the script as root or wam. please tell me if this will work #!/bin/bash sudo -t wam /usr/local/wam/stopwam -r ------- this needs run as wam user /usr/local/web/stopweb -a --- this needs to run as... (18 Replies)
Discussion started by: nanz143
18 Replies

4. Shell Programming and Scripting

Script for running root based C++ code

Hi all, I have to run C++ file using root programming, using following commands: $root -l root .L TwoTrees.C++ root TwoTrees t root t.Loop() root.q I wonder if I can write script to do the following. Thanks Pooja (12 Replies)
Discussion started by: nrjrasaxena
12 Replies

5. Shell Programming and Scripting

Issue running script as root

1) Environment:Red Hat Linux, bash shell Script to be run owned by user :myUser Home environment of myUser: pathto/home 2) ESP agent with root access will run JobXXX.sh su - myUser -c "/pathto/home/bin/script.sh" where script.sh has some echo statements and an exit statement in the end... (4 Replies)
Discussion started by: cj09
4 Replies

6. Shell Programming and Scripting

Running script and commands through SSH

Hello All, I am trying to run some simulations through SSH from my mac on our university SOLARIS system. My problem is that whenever I want to execute a command I get an error which says "Invalid argument". Maybe I should explain more what I want to do and what I did. Firstly I installed a... (10 Replies)
Discussion started by: Apfik
10 Replies

7. Shell Programming and Scripting

Create script for change root password via SSH

HI I 'm new shall script and unix. I want to create script for change password root by ssh-keygen command . I have 50 servers and I want ot login ot the servers via ssh by type ones password and can login every machines.The script ssh-keygen must ot generate key every weekly than it send new... (2 Replies)
Discussion started by: pellnapook
2 Replies

8. Shell Programming and Scripting

As root , running script as different user with su - problem

Dear All I am running into a situation where I am running a script as another user lets say oracle using su command as below, and the script fails because the .profile of oracle is not executed so the environment variables are not set. cat /etc/passwd | grep oracle... (4 Replies)
Discussion started by: dbsupp
4 Replies

9. Shell Programming and Scripting

Script to verify SSH is running

Writing a simple test script that looks for ssh, kills if its running and verifies if its still running. If it isn't, move on. My issue, its cause I don't know how, is to verify if ssh is running still. Also, is there a way have this do this on a remote server? I already have the ssh keys... (7 Replies)
Discussion started by: djinn
7 Replies

10. Shell Programming and Scripting

Running a command or script as root

I'm writing an application (Progress language) that needs to: 1) load the contents of a cron table into the Progress application; 2) display this information in a human manner and allow a select group of people to update it (these people are logged in as themselves, not as root); 3) save... (3 Replies)
Discussion started by: rm-r
3 Replies
Login or Register to Ask a Question