Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-07-2009, 05:48 PM   #1
LQ Newbie
Registered: Aug 2009
Posts: 1

Rep: Reputation: 0
Question about SSH


I'm trying to make either a single command or a shell script that I can run that will SSH into another box, login as root, then execute a shell script on the remote box.

I've been trying to make one, however I've been unsuccessful so far. Any suggestions?

Much appreciated!
Old 08-07-2009, 07:26 PM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
If you just want to run a command as root (i.e. without logging in and running .bash_profile) then sudo's probably the easiest way:
ssh user@server.domain sudo command
I just tried that on my Ubuntu box, and it worked - although it did print the admin password the second time. You could always configure sudo to allow the user to run the specific command without a password.

You can't run su from the ssh command-line, because it needs a terminal of some sort. You could create a virtual terminal, then attach it to the standard input and output streams provided by sshd, but that's much more work than the sudo route.

Hope that helps,

—Robert J Lee
Old 08-07-2009, 07:45 PM   #3
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
You could also setuid your script and run it as an unprivileged user. This avoids the security problem of allowing your account to gain root on that server without a password, but that means you need to be super careful about who can write to that script.


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
ssh question tronica Linux - Server 3 06-24-2007 08:27 AM
ssh-agent/ssh-add question mega Slackware 2 01-26-2005 04:09 AM
SSH Question JockVSJock Slackware 2 11-11-2004 08:00 PM
Question on SSH ? brokenflea Slackware 7 10-27-2004 10:25 AM
question about ssh minor Linux - Security 7 05-20-2001 09:24 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:57 PM.

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