April 06, 2012

Built trust ssh key on Hpux

usr/bin/ssh-keygen -t rsa
usr/bin/ssh-keygen -t dsa

Sometime to automates your script you'll to copy some file via scp or sftp or may you get bored to ssh to same server everyday and asking you the same password. Here's how to automated your scp, sftp, and ssh to login without password

1. Go to your home folder
CODE:
$ cd ~

2. Pass this step if you already has .ssh folder
CODE:
$ mkdir .ssh

3. Set private
CODE:
$ chmod -R 0700 .ssh

4. Go to your ~/.ssh folder
CODE:
$ cd .ssh

5. Create a ssh public_key
CODE:
$ ssh-keygen -t dsa -f id_dsa -P ''

6. Copy PUBLIC key ONLY to .ssh folder on target server
CODE:
$ scp id_dsa.pub user@server:~/.ssh

7. Now log into the remote server as the target user
CODE:
$ ssh user@server

8. Go to it's .ssh folder
CODE:
$ cd .ssh

9. Put your public key in the authorized keys file
CODE:
$ cat id_dsa.pub >> authorized_keys2

10. Set privates the authorized_keys2
CODE:
$ chmod 0600 authorized_keys2

11. Delete the public key on the remote server
CODE:
$ rm id_dsa.pub

12. Exit the server
CODE:
$ exit


Now if everything is correct you should be able to ssh, scp and sftp to target server without password
CODE:

$ ssh user@server
$ scp testfile.txt user@server:/data



And For Notes :

1. Home directory should have 755 permission (users home directory)
2. $HOME/.ssh directory should have 700 permission
3. $HOME/.ssh/authorized_keys file should have 600 permission

No comments:

Post a Comment