How to connect unix server to unix server through shell scripts

Hi,
I would like to connect UNIX server to UNIX server through shell scripts
and i have some concepts . But i am totally confused how to connect UNIX
server to UNIX server throuth running a script. It will be greatful to me if
any buddy will help me.

with simple example please.

Thanks in advance,
Phatn :slight_smile:

You'll need to elaborate on what you are trying to do (eg Run commands on another server? Transfer a file? Check the status of another server?) but the basis would be as follows:

#!/bin/sh
desthostname=<where you are connecting to>
destusername=<username you are connecting as>
commandtorun=<command to run on the destination server>
ssh $destusername@$desthostname $commandtorun

Then (on the destination server) create an authorized keys file (~/.ssh/authorized_keys) containing the public ssh key found in your source server's ~/.ssh/id_dsa.pub (or something similar) file.

This will allow passwordless connection between the two users on the two servers.

This all assumes you are using ssh of course and that you are trying to run a command on teh remote host. Fill in more details if this is not the case.

if you would like to ssh from 1st server to 2nd server
1.Login into 2nd server using the 2ndserveruser and create a directory named .ssh (note . before ssh) under the home directory .
2. Login into 1st server and go to .ssh directory.
3. Run the following command from this directory
ssh-keygen -t rsa
This would prompt for the filename to which the key to be stored.A default value is given in brackets as id_rsa. So just press RETURN to continue. Next it would ask for Passphrase. Press RETURN to continue. Again it would ask for same passphrase again. Again press RETURN to continue.This would generate key pair and stores it in id_rsa file.
4.Exit from this .ssh directory (cd ..)and go back to home directory.From the home directory run the following command:
cat .ssh/id_rsa.pub|ssh 2ndserveruser@2ndserverIP 'cat >> .ssh/authorized_keys'