Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 09-08-2007, 04:45 AM   #1
LQ Newbie
Registered: May 2007
Posts: 13

Rep: Reputation: 0
Program that logs in on remote computer via ssh and executes commands on it

I am a network administrator and i want to write a program that can log in on remote computers via ssh and then execute certain commands on it.

What i want to know is:
1. how to make the program log in.
2. how to execute the commands.

Last edited by harrybazeegar; 09-08-2007 at 04:48 AM.
Old 09-08-2007, 06:42 AM   #2
Alien Bob
Slackware Contributor
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 7,914

Rep: Reputation: 6584Reputation: 6584Reputation: 6584Reputation: 6584Reputation: 6584Reputation: 6584Reputation: 6584Reputation: 6584Reputation: 6584Reputation: 6584Reputation: 6584
First configure a public/private key pair for passwordless ssh-logins. This is what you need before you can write unattended scripts.
Look at these google hits, the process is well-documented: ssh private key setup

Once you have a key - assume that the key for your remote ssh server is "/home/alien/.ssh/myremoteserver" - you use a "here-document" to run the remote commands:
ssh -i "/home/alien/.ssh/myremoteserver" -l alien <<EOT
cd public_html
ls -la
Using ssh-keys it is also possible to copy files between the two sites unattended (nice for backups):

rsync -va -e "ssh -i /home/alien/.ssh/myremoteserver -l alien" .
Old 09-08-2007, 07:14 AM   #3
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
not a networking question. moved to Linux - software. additionally you might like to look at a tool like dsh which allows you do do as above to multiple systems at once.


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
store squid logs in a remote computer mariogarcia Linux - Server 1 05-10-2007 06:04 AM
ssh onto remote computer (issues) tuxhats Linux - Networking 3 06-06-2006 10:11 AM
ssh running remote commands Nikee Linux - Security 5 02-04-2006 03:00 AM
execute multiple ssh remote commands tom221 Linux - Newbie 2 01-28-2005 01:00 PM
remote ssh commands on multiple hosts evilchild Linux - Software 6 08-12-2004 10:48 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:48 AM.

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