"Innovation comes only from readily and seamlessly sharing information rather than hoarding it."- Tom Peters
Development Blog

The Easy way for Key Based Authentication for SSH

Why use a key-based system?

Using a key-based system makes it much faster, and even more secure to ssh into a server, and scp files onto a remote server. To do this is pretty easy...

How?

  1. On your local machine, create a .ssh in the home directory (if you don't have one already).
    mkdir ~/.ssh
    
  2. Go inside the folder.
    cd ~/.ssh
    
  3. Run the ssh-keygen command. This will create a set of public and private keys.
    ssh-keygen
    
    When asked for the name, you can name it whatever you like. For example, I could name one michael_theirwinfamily_net for me to use on this site. When asked for the passphrases, feel free to leave them blank.
  4. Copy your public key to the server. Use the following command (replace the name of the public key with your real filename, and the host name with your real host)
    ssh-copy-id -i [path to .pub file] [remote-host]
    ssh-copy-id -i ~/.ssh/michael_theirwinfamily_net.pub michael.theirwinfamily.net
    
    You will need to enter your password to log in to the server, after which your key will be added!
  5. Now, ssh to your server, and you shouldn't need to enter your password!

Other ideas/troubleshooting

  • If you wish, you can use the same public key for various domains, hosts, etc.
  • Don't forget that if your username is not the same as the one you use on the server, use username@hostname for the [remote-host] part of the ssh-copy-id command. For example:
    ssh-copy-id -i ~/.ssh/michael_theirwinfamily_net.pub example@michael.theirwinfamily.net
    

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".

More information about formatting options