LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 09-24-2010, 09:25 AM   #1
felton57
Member
 
Registered: Aug 2007
Posts: 35

Rep: Reputation: 15
SSH Script to replace RSH Script


Here is my dilemma:

I want to shutdown a number of computers in my lab. Hostnames are jmud1, jmud2, jmud3 and jmud4 .... jmud20.

Current script or command used:

#!/bin/csh

foreach num (`/root/tools/machines`)
rsh jmud{num} /sbin/shutdown -hy 0 &

end

#End of Script

The file "machines" have the numbers of my hosts 1 - 20.

How do I replace is with ssh or something useable in RHEL5?

Last edited by felton57; 09-24-2010 at 09:26 AM.
 
Old 09-24-2010, 09:44 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Change the "rsh" to "ssh" in the script on the source host.
On the source host you have to generate a key with ssh-keygen (e.g. ssh-keygen -t dsa) as the user that will run the script. Typically this will put the public and private keys in user's $HOME/.ssh directory.

On all the target hosts (jmud1, jmud2 etc...):
1) Remove all the user .rhosts files to prevent rsh from working. (Not required to get ssh working but a damn good idea from a security standpoint.)
2) Setup ssh trust from the server where you're running the script to this target by creating $HOME/.ssh for the user on the target host and create an authorized_keys file in there. Put the contents of the public key from the source host in this.

After that do an ssh to each of the targets from the source so it will prompt you to store known hosts' keys on the source and not ask during the script run.

Note:
$HOME must be writable only by the user but can be accessible by all. $HOME/.ssh must be read/write only by the user and no one else. If this isn't the case then you will still be prompted for password which defeats the point in establishing the trusts.
 
1 members found this post helpful.
Old 09-24-2010, 10:06 AM   #3
felton57
Member
 
Registered: Aug 2007
Posts: 35

Original Poster
Rep: Reputation: 15
I will try it.

Thank You!
 
  


Reply



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
Rsync gives an rsh error when running in a script codenjanod Linux - Software 2 11-25-2009 08:55 PM
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 04:50 PM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10:37 PM
rsh script to run on cluster podollb Linux - Networking 3 03-10-2004 10:22 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

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