LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-10-2009, 08:22 AM   #1
martinhb
LQ Newbie
 
Registered: Nov 2008
Posts: 5

Rep: Reputation: 0
How to ssh as root to a workstation and then run commands as another user.


Senario is we have a system where root has authorised keys set up so that it can do a passwordless ssh to $WORKSTATION. I then need to run a script on $WORKSTATION as user "bob" and NOT as user "root". I do not want to set up user "bob" to be allowed passwordless ssh so any ideas how I can do this?

I have tried variations of (as user "root"):

ssh $WORKSTATION "su - bob; ./my_script"

Just hangs unfortunately.

Thanks
 
Old 06-10-2009, 08:51 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
ssh $WORKSTATION 'su - bob -c "$PWD/my_script"'
 
Old 06-10-2009, 10:22 AM   #3
martinhb
LQ Newbie
 
Registered: Nov 2008
Posts: 5

Original Poster
Rep: Reputation: 0
ssh $WORKSTATION 'su - bob -c "$PWD/my_script"' appears to run the command on the local machine as it says it cannot find the script which is located on the $WORKSTATION.

Should the command be:

ssh $WORKSTATION 'su - bob -c "$WORKSTATION:/my_script"`

Thanks
 
Old 06-10-2009, 08:56 PM   #4
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
No, the command should not be that. Try providing the fully qualified path (rather than a relative path) for your script.

example: /foo/bar/my_script
 
Old 06-10-2009, 09:04 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
I think the $PWD is getting read before the ssh cmd is issued.
You'll have to check the bash docs for order of interpolation.
Using $WORKSTATION won't change that.
If the script is in a constant place, just use the absolute value of the path, or set it as a variable (maybe an input var) in the call to the script that runs ssh.
 
Old 06-10-2009, 10:04 PM   #6
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Code:
ssh $WORKSTATION "su -c <command> bob"
Where command is the full path to the command.
 
  


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 run a set of commands through ssh vickylife Linux - Newbie 8 11-13-2008 06:48 PM
getting SSH commands to run as local r00tb33r Linux - Software 2 02-02-2008 11:58 PM
run a specific script with root privilege as any user(possibly with ssh) z940303 Programming 5 09-05-2007 08:20 PM
How a ordinary user can run commands having only root privilige in C? shivaligupta Programming 1 01-31-2005 04:24 AM
im in user mode and cant run hdparm and ifconfig commands, but if im root, i can. kublador Linux - Newbie 2 09-12-2003 08:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 03:13 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