Home   >>   SSH   >>   Using SSH Keys in Linux
Using SSH Keys in Linux PDF Print E-mail
( 0 Votes )
How To - SSH
Written by Christian Foronda   
Thursday, 07 January 2010 11:58

 

Using SSH keys is very handy for not always having to enter your password when logging into SSH. I'll show you how to set this up.

  1. Generate the key by running:
        ssh-keygen -t rsa
    
    • Press enter to accepted the default location of ~/.ssh/id_rsa
    • Enter your passphrase. Make it as secure as possible.
  2.  

  3. On my server, I have SSH running under a different port from the default, so I modified ~/.ssh/config as follows, obviously with different values:
        Hosts example.com
        Port 22000
    
    • To fix the permissions, execute:
          chmod 600 ~/.ssh/config
      
  4. Transfer ~/.ssh/id_rsa.pub to the remote server:
        scp ~/.ssh/id_rsa.pub 
     This e-mail address is being protected from spambots. You need JavaScript enabled to view it
     :~
    
  5. Then, SSH to the remote server:
        ssh 
     This e-mail address is being protected from spambots. You need JavaScript enabled to view it
     
    
  6. Add the public key to the list of authorized keys:
        cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
    
  7. Fix the permissions:
        chmod 600 ~/.ssh/authorized_keys
    
  8. Delete id_rsa.pub:
        rm -f ~/id_rsa.pub
    
  9. Now you can exit the remote server:
        exit
    
  10. Now, run ssh-agent so you only have to enter the key once:
        ssh-agent -s > ~/.ssh-agent
    
  11. Bring the environment variables from ~/.ssh-agent into the current shell:
        source ~/.ssh-agent
    
  12. Add the key to ssh-agent:
        ssh-add
    

    When prompted, enter your passphrase, as you entered in step 1.

  13. Now, you should be able to run:
        ssh 
     This e-mail address is being protected from spambots. You need JavaScript enabled to view it
     
    

    Without being prompted for your password.

Ref: http://www.perpetualseeker.com/?p=489

 




blog comments powered by Disqus