Running A Program On A Remote Server Using Ssh
|
How do you run a program on a remote server using ssh?
For this example we'll have two servers, one named Johnny and another named Cash. Both are running openssh. Our goal is to have a program on Johnny login to Cash and run a program on Cash. To make the task a little more complex we'll be using different users on each machine.
The first thing we'll need to do is generate public and private keys on Johnny. So, logged into Johnny as user 'boy' we create public and private keys by creating them in the .ssh directory as follows:
Johnny$> pwd
/home/boy/.ssh
Johnny$> ssh-keygen -t rsa -f sue
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in sue.
Your public key has been saved in sue.pub.
The key fingerprint is:
8d:e9:c0:g1:c7:1f:e3:b3:2f:38:12:aa:b5:3b:2e:b3 boy@Johnny
Johnny$>
In the example above we picked an arbitrary name, sue, to identify the files that hold the generated keys. When prompted to enter a passphrase (twice) we simply hit enter twice.
As the output of ssh-keygen indicates, the public key has been saved in a file named sue.pub.
The output of ssh-keygen implies, but doesn't indicate directly, that the private key is in a file named sue (Yes, a user named boy created a file named sue.)
Johnny$>ls -l
-rwx------ 1 sue suegrp 887 Oct 17 14:27 sue
-rwx------ 1 sue suegrp 223 Oct 17 14:27 sue.pub
The private key file, sue, will remain on Johnny for the reaminder of this exercise, but the public key must be moved to the remote server, Cash. Note that the .ssh directory itself, as well as the sue and sue.pub files should have permissions of 700.
Now you'll need to ftp the sue.pub file from Johnny to Cash. The user on Cash that we'll login as is user 'named'.
Johnny$> ftp Cash
Connected to Cash
220 Cash - Propery of Xyz. - Authorized users only
Name (Cash:boy): named
331 Password required for named.
Password:
230-Last unsuccessful login: Fri Oct 17 13:12:55 2003 on ftp from Johnny 230-Last login: Fri Oct 17 16:02:11 2003 on /dev/pts/1 from Johnny
230 User named logged in.
ftp> cd .ssh
ftp> mput sue.pub
mput sue.pub? y
200 PORT command successful.
150 Opening data connection for sue.pub.
226 Transfer complete.
224 bytes sent in 0.000781 seconds (280.1 Kbytes/s)
local: sue.pub remote: sue.pub
ftp>bye
221 Goodbye.
Johnny$>
Now we'll telnet into Cash and concatenate the sue.pub file into /home/named/.ssh/authorized_keys file.
Cash$> pwd
/home/named/.ssh
Cash$> cat sue.pub >> authorized_keys
Cash$> exit
Connection closed.
Johnny$>
Let's recap what we've done so far.
1) We've created public and private keys on Johnny.
2) We've ftp'd the public key file, sue.pub, from Johnny to Cash.
3) We've telnetted to Cash, and concatenated the contents of sue.pub into authorized_keys
We're now ready to manually login from Johnny to Cash using ssh.
Johnny$> ssh -i /home/boy/.ssh/sue named@Cash
The authenticity of host 'Cash (xxx.yyy.zzz.aaa)' can't be established.
RSA key fingerprint is 65:11:7d:ef:ed:a3:cc:34:d1:b5:ba:c9:16:22:31:23.
Are you sure you want to continue connecting (yes/no)? yes
*** NOTICE TO ALL USERS ***
Cash$>exit
Connection to Cash closed.
Johnny$>
Now on Johnny, create a shell script called 'boynamedsue.sh' with the following one line of contents and chmod the script to 777.
ssh -i /home/boy/.ssh/sue named@Cash /usr/bin/ls -l
Next, execute the script on Johnny.
Johnny$> boynamedsue.sh
*** NOTICE TO ALL USERS ***
-rwxrwxr-x 1 named namedgrp 10020 Oct 17 14:35 namedfile1.txt
-rw-r--r-- 1 named namedgrp 680 Aug 14 16:18 namedfile.html
-rw------- 1 named namedgrp 1148 Aug 18 09:51 mbox
drwxr-xr-x 2 named namedgrp 512 Jun 17 13:38 old
Johnny$>
You just executed a program on Johnny, that logged into Cash and ran a program (unix 'ls -l').
The next step you'll want to take is to replace the '/usr/bin/ls -l' command in the boynamedsue.sh program with the path and name of the program that you want to run.
About The Author
C.S. Deam is a small business owner. His eBook Computer Nuggets: Non-Techie Internet Tips For In-Laws, Out-Laws, and the Rest of Society is a great gift for non-techie family members and is available at www.LinkertonPublishing.com where you can sign up for FREE E-Courses & Newsletters to help you on your path to self-employment.
|
|
|
Beware Of Spyware
One day, you suddenly realize that your computer started to worknoticeably slower than it used to. You decide to run de-fragmentation of your hard drive and add more virtual memory to the system. No luck! May be, it's probably some viruses, you reckon turning on your virus scanning software. Even after running the anti-virus program you notice that the problem won't resolve. Not understanding what's happening frustrated you pick up the phone. It's time to call your tech-support. Sounds familiar? You are not alone! Each day, thousands of users are facing similar problems caused by malicious software called Spyware. According to Dell technical support...(related: Software)
Microsoft Great Plains Customization: Project Organization ? International Business Example
Microsoft Business Solutions Great Plains fits to majority of horizontal niches and clientele in the USA, Canada, Mexico, Latin America, U.K., Brazil, South Africa, Australia, New Zealand and Middle East. If you are project organization: Real Estate, Law Firm, Placement Agency with permanent clients, Construction or Freight Forwarding company ? you probably use or plan to deploy Project management or Project accounting extension for Microsoft Great Plains. If you have...(related: Software)
Navision Customization: C/side, C/odbc, C/front, Xbrl ? Development Options
Microsoft bought Navision, Denmark based software development company, along with Great Plains Software. Now Microsoft Business Solutions offers following ERP applications: Navision (former Navision Attain), Microsoft Great Plains (former Great Plains Dynamics/eEnterprise), Solomon, Axapta. Formerly Navision had strong positions in Europe. Now it is promoted in USA and Europe. Navision has pretty advanced manufacturing module.We would like to give you: programmer, software developer, database administrator the ori...(related: Software)
Corporate Erp: Microsoft Great Plains For The Plant In Brazil ? Overview For Cio
Microsoft Business Solutions Great Plains as new ERP for multinational corporation manufacturing facility in Brazil.If your company plans to outsource manufacturing in Brazil by purchasing existing facility there, the first step would be to implant new management team and revise business processes and procedures. The way there comes through the new ERP/accounting system implementation from scratch. We'll show you the way to implement new system on the base of Microsoft Great Plains. You may have two reasons to place Great Plains, first ? you company has Great Plains implemented in the headquarters and this is worldwide policy, second ? if you have high end ERP at the headquarte...(related: Software)
Benefits Of Shareware
Shareware has been fighting the stigma of being misunderstood for decades. While corporate software giants can no longer ignore the marketing potential of a trial version, small software startups are struggling with new listings and bandwidth costs. Businesses and individual consumers need to take a closer look at the benefits of taking advantage of shareware marketing. The concept of a trial version is not a new one. Consumer expectations, and the need for immediate satisfaction have spurned the industry to realize the need for instant software. The availability of file downloads in the Internet era, is spurning a revolution of purchasers who never leaving their homes or offices. As a result, the Internet has taken the proliferation of shareware to a new level.Why the Success?Why developers have succeeded using shareware market...(related: Software)
The Software 2005 Conference - A Review
The Software 2005 conference is now a wrap. This conference, presented by M.R. Rangaswami and The Sandhill Group, is now an annual event and attendance increased 35% this year over 2004. It is an ideal opportunity for those in the enterprise software industry to see what's new and what's coming, as well as to catch up with old colleagues and make new connections. It is also a perfect forum for startups to gain exposure as well as solicit funding and key partnerships.According to Sandhill, there were 1500 attendees this year, including 100 ...(related: Software)
Microsoft Great Plains: Offshore Customization & Development ? Overview For Consultant
When you visit department stores and see that majority of the apparels are produced in other countries, not US ? you probably do not worry about this fact. About 10 years ago, when Clinton's high tech era was at the inception ? we saw the signs of high tech professionals inflow in the USA from overseas. Nowadays the trend is reversed ? instead of importing high tech people, we are at the beginning of outsourcing to them in their overseas countries the programming workload. In this small article we'll concentrate on the Microsoft Business Solutions Great Plains customization specifics: Great Plains Dexterity (ID...(related: Software)
History Of Java
The java programming language is becoming more and more popular each day. It is the language without which one cannot even hope to a land a job thesedays. But has somebody even wondered how this language came about? There are many stories about, many books have been written. Here is my version (not approved by Sun Microsystems).The java programming language originated in Indonesia. It was meant to be usedby the tourists that visit that country each year. Why would tourists want to use computer? Well, these ar...(related: Software)
Internet Security Threats: Who Can Read Your Email?
Before being able to choose a secure Internet communication system, you need to understand the threats to your security.Since the beginning of the Internet there has been a naive assumption on the part of most email users that the only people who are reading their email are the people they are sending it to. After all, with billions of emails and gigabytes of data moving over the Internet every day, who would be able to f...(related: Software)
site-map - Copyright © 2008 | Contact Webmaster | All Rights Reserved. | Software