4/17/16 - Fixed formatting. 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 id_rsa.pub >> .ssh/authorized_keys
cat: id_rsa.pub: 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.
ls ~/.ssh
known_hosts
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 id_rsa.pub >> .ssh/authorized_keys
Optional, but I recommend removing the key since it’s no longer needed.
rm id_rsa.pub
Restart the service.
sudo service ssh restart