Can Not Add SSH Key To Ubuntu

I wanted to add an SSH key to a new minimal Debian VM install, but attempting to add the key resulted in a No such file or directory error.

# sudo cat >> .ssh/authorized_keys

   cat: No such file or directory

The error was the result of the non-existent authorized_keys file which is where SSH key happens to be stored.

If we look inside the ~/.ssh directory you will notice the missing authorized_keys file.

# cd ~/.ssh

# ls


To be able to store the SSH key create the missing authorized_keys in the right location and with the right permission.

Move to the directory where key files are stored for the user.

# cd ~/.ssh

Create necessary file.

# touch authorized_keys

Assign permission to file.

# chmod 600 authorized_keys

Copy SSH key to authorized_keys file.

# cat >> .ssh/authorized_keys

Optional, but I recommend removing the key since its no longer needed.

# rm

Restart the service.

# sudo service ssh restart