LinuxMoz

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.

1
scp ~/.ssh/id_rsa.pub [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:

1
chmod 600  ~/.ssh/id_rsa.pub

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:

1
cat id_rsa.pub >> authorized_keys

If the file does not exist enter the following commands:

1
2
3
4
cat id_rsa.pub > 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.

Comments