ssh key authentication

How to generate SSH keys and implement for key authentication.

login to local machine with user you will be using for connect to remote.

1. generate keys:
ssh-keygen -t dsa

2. copy to remote machine to /tmp directory
scp ~/.ssh/ remote_machine:/tmp

3. login to remote machine and append new key to authorized_keys2 file in home folder
cat /tmp/ >> ~/.ssh/authorized_keys2

4. log out and that it is.

You can try with:
ssh remoteuser@remoteserver
and you will be connected to remote server without password.

This entry was posted in Linux tips and tagged , , . Bookmark the permalink.

2 Responses to ssh key authentication

  1. Hi Franz,
    When I want to do step 2 on the remote server
    scp ~/.ssh/ remote_machine:/tmp

    I get this error:
    “bash: /.ssh/authorized_keys2: No such file or directory”.

    What should I do?

  2. Noel says:


    Not sure if you still need this, but try this.
    1st see if the .ssh directory exist with: ls -la ~
    If it does not exist, you will need to create it with the following command: mkdir ~/.ssh
    Now you will need to chmod it to 700. Use the following command: chmod 700 ~/.ssh

    Now run the following to append the to authorized_keys2. Do this with the following command: cat /tmp/ >> ~/.ssh/authorized_keys2

Leave a Reply

Your email address will not be published. Required fields are marked *