LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-08-2007, 04:45 AM   #1
harrybazeegar
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: 8,559

Rep: Reputation: 8114Reputation: 8114Reputation: 8114Reputation: 8114Reputation: 8114Reputation: 8114Reputation: 8114Reputation: 8114Reputation: 8114Reputation: 8114Reputation: 8114
Simple.
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:
Code:
ssh -i "/home/alien/.ssh/myremoteserver" -l alien some.remote.net <<EOT
ls
cd public_html
ls -la
EOT
Using ssh-keys it is also possible to copy files between the two sites unattended (nice for backups):

Code:
rsync -va -e "ssh -i /home/alien/.ssh/myremoteserver -l alien" some.remote.net:mydailybackup_20070908.tar.gz .
Eric
 
Old 09-08-2007, 07:14 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
  


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
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:09 AM.

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