1820260 Members
3011 Online
109622 Solutions
New Discussion юеВ

ssh without password

 
SOLVED
Go to solution
Sachin_48
Occasional Advisor

ssh without password

Hi all

I want to run the ssh commands using script but it becomes interective as it needs password to be entered Pls help me how to enable the public private key . So that the ssh will not ask for password every time.

I have tried with public and private key but it does't worked or may be I was using it wrongly .

Pls give me the procedure also to do so.

Regards
Sachin Rajput
HCL
4 REPLIES 4
Sivakumar TS
Honored Contributor
Solution

Re: ssh without password


Hi Sachin,

it can be done..

here is a procedure which got from Net.

Passwordless SSH using public/private keys

Including how to set up rsync and unison (syncronisation software)
Here is a list of the steps that I had to do to get automatic replication of /home/folder1 (or any other folder) on one server to /home/folder2 on another server:

Passwordless SSH
To get replication working securly you firstly need to be able to connect via SSH without using passwords:

First server setup
ssh-keygen -t dsa(press enter twice to give a blank password)

cd
cd .ssh
vi .configPress "i" to enter insert mode and copy this into the file:

Host remotehost
User remoteuser
Compression yes
Protocol 2
RSAAuthentication yes
StrictHostKeyChecking no
ForwardAgent yes
ForwardX11 yes
IdentityFile /home/localuser/.ssh/id_remotehost_dsaDo NOT change the last line - it is supposed to say remotehost (not an actual host name). the remoteuser specify as the other username Now,

:wq(save and exit vi)

vi id_dsa.pubIt should look like this:

ssh-dss AAAA..............v root@HOSTNAMEOFSRV01where there is lots of random letters/numbers where the dots are. Select it all and copy it. Make sure that it is all on one line with no spaces at the start or finish (which will happen if you copy it using putty on windows; test it by pasting it into notepad)
Tip: To copy from putty on windows select the text from within vi and pres Ctrl + Shift. To paste text enter insert mode and press the right mouse button. (best way would be to copy the file through scp)

Second Server Setup
cd
vi .ssh/authorized_keysEnter insert mode (press i) and paste the key, again ensuring that there are no spare newlines or spaces. Save the file and exit vi (press :wq then return, as above)

Testing passwordless SSH
On the first server, type

ssh -l other_user_name srv02


Hope this is useful,

Siva.
Nothing is Impossible !
Abhijit P.
Valued Contributor

Re: ssh without password

Hi...

Try this this works !!!
Generate a key pair using ssh-keygen, copy the public key to the remote host and place it in .ssh/authorized_keys (or authorized_keys2 for an SSH2 key). Then copy the private key to .ssh/identity on your local machine. Now everything├в s set for unhindered ssh├в ing.

Regards,
Abhijit


Arunvijai_4
Honored Contributor

Re: ssh without password

Hi Sachin from HCL,

Check this document for setting up SSH without password.

"A ship in the harbor is safe, but that is not what ships are built for"
Sachin_48
Occasional Advisor

Re: ssh without password

Thanks you all

I got the solution

Regards
Sachin Rajput
HCl