Sunday, January 20, 2008

Using ssh, scp, sftp without password

SSH is a remote access protocol that designed for security purpose, replacing non-secured Telnet. As it main strong point is its security, there's both side signature and authentication to establish a connection. And also, if you notice, most SSH clients didnt offer a "remember password" option and always been asked for password each time you want to connect.

But on linux you can set the connection establish itself without prompting for password. This quite useful if you very often connect to a server. I assuming connecting from LOCAL to SERVER.

1. Log on to LOCAL computer. Run following command :
$ ssh-keygen -t dsa
Left the field empty (press enter to accept the value)
As this step complete, there are 2 file created in your home ~/.ssh/ folder
id_dsa.pub --> this is your public key
id_dsa --> this is your private key

2. Merge the public key into SERVER's authorized key. First we need to transfer the file first using SCP. Add -P option if your SERVER user other port than default SSH port 22.
$ scp ~/.ssh/id_dsa.pub user@SERVER:/tmp
Then, log on to SERVER for further step by
$ ssh user@SERVER -p port_number
Change the port number to a value of your SSH port. If you dont know you may try 22.

3. As we logged on SERVER, merge the public key into authorized_key2 :
$ cat /tmp/id_dsa.pub >> ~/.ssh/authorized_key2
Now you can delete the public key :
$ rm /tmp/id_dsa.pub

4. Now you can SSH, SFTP or SCP to SERVER from LOCAL computer without get prompted by password.

For security reason, please apply this for trusted computer only.

8 comments:

Anonymous said...

tambahan:

jika file 'authorized_keys2' tidak ada create dengan touch atau degan 'cat' tadi juga bisa lgs ada

Anonymous said...

'authorized_keys2' didej pratak de vonefer lungi vide marh kude jo

says said...

English/Indonesian please :)

Sahed said...

This is good steps
if u give us total steps then it will more help for us.
Thanks

Sahedunix said...

Thats great Dear
thanks to you
Visit weballinfo

Anonymous said...

Is it possible to write a script to transfer files with rsync over sftp? The access IP directory has been assigned to logon as sftp connectioin.

says said...

Yes possible, but first time you need to bypass the password prompt, as instruction above.

Anonymous said...

I generated the ssh-keygen for local server( the server which I want to invoke using sftp i.e., fsx03.fox.com). Now I wrote script in my remote server by invoking that server using sftp. Still its prompting for password.

for your reference

fsx03.fox.com -- local server
xxx06.yyy.com -- remote server


Eg::

ExForSSHKeyGen.sh

sftp gk08009@fsx03.fox.com
cd Sample
put text

Output

Password:
sftp>

Please help me out