How to add SSH public key authentication in Linux

It’s pretty easy, but every time I have to look up the right permissions for .ssh and the authorized_keys file. The solution is described on StackOverflow and the OpenSSH FAQ:

mkdir ~/.ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

# now paste the user's public key here:
cat > ~/.ssh/authorized_keys

done.