I'm trying to send the public id_rsa.pub file from my Mac to the ~/.ssh/authorized_keys directory in my home directory at Linux servers so I can then access without logging in each time.
From my Mac Terminal I'm using this command:
cat ~/.ssh/id_rsa.pub | ssh username@remoteserver 'cat >> ~/.ssh/authorized_keys'
This works if the remote ~/.ssh directory already exists, but doesn't otherwise. In that case I have to first login to the remote server, create the .ssh directory, then logout, and then run the above command. After that I can ssh to the remote server without logging in.
I need to do this for a few dozen servers, so I was wondering if there was a way of modifying the above command to create the remote .ssh directory if it wasn't already present.