Hello,
You have two possible solutions for that, one is to work with the SSL keys.
CD into directory /root/.ssh. First create the key-pair that will be used to authenticate.
Code:
ssh-keygen -t dsa -b 1024
the output is shown below
Code:
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Hit <enter> here to accecpt the proposed name or type in a new filename to use.
Code:
Enter passphrase (empty for no passphrase):
It's very important to just press enter here to create a key with an empty password. If you don't do this and type in a password the program will fail because it will ask for a password every time it launches.
Code:
Enter same passphrase again:
Hit enter again to confirm the empty password.
Code:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
ab:03:b9:9c:61:58:f1:70:f4:58:6a:0c:5e:b3:92:b4 root@srvtradupg
The key's randomart image is:
+--[ DSA 1024]----+
| o.+ . |
| oo*.B |
| E=* . |
| .o. |
| o . S |
| . = . |
| o = . |
| + .. |
| .. |
+-----------------+
this is the final output and the key's are generated. The example above is just that, an example and always is different. It's a random key that will be compared between the keypair to authenticate.
If you followed the steps as indicated above you'll have two files in your /root/.ssh directory, named id_dsa and id_dsa.pub. Copy the id_dsa.pub file over to the second server SERVER2 in the /root/.ssh directory.
Login on the second server and CD into the /root/.ssh directory. Perform the following command to add the key to the authorized_keys file.
Code:
cat id_dsa.pub >> authorized_keys
From now on you can open an ssh tunnel from SERVER1 to SERVER2 without the need for a password. Try it out using the following command.
If all is well you get the prompt at SERVER2 without having to enter a password.
The other option is to use a tool called sshpass, download and install the program to your server and in your script or from the command line use this to connect without having to type your password.
Code:
sshpass -p 'thepassword' ssh root@SERVER2 'yourcommand'
Kind regards,
Eric