Linux Stuff && Coffee

How to Copy SSH Public Key From a Mac to a Linux Server

| Comments

In order to login to your Linux Server over SSH from a Mac you must first copy over your Public key and Mac OSX does not come with the ssh-copy-id command so you need to copy the public key from Mac OSX to the Linux server manually.

Copy SSH Public Key to Linux from Mac OSX

This assumes you have access to the remote server via password based authentication (typing in a password), to start with lets copy the key over.

scp ~/.ssh/ [email protected]:/home/username/.ssh/

(Your key name may differ)  If the .ssh directory does not exist on the remote server you will need to login and create it.

Now the key has been copied from the mac to the REMOTE Linux server.

Set correct permissions for the SSH Public Key on the remote server:

chmod 600  ~/.ssh/

Next add the key to the SSH authorized_keys file, if the file does not exist create it.

If the file authorized_keys already exists in ~/.ssh the use the following command:

cat >> authorized_keys

If the file does not exist enter the following commands:

cat > authorized_keys
chmod 600 authorized_keys
chown kjs:kjs authorized_keys
vi /etc/ssh/sshd_config

You should now be able to login to the Linux server using SSH key based authentication from your Mac.