The following instructions explains how to connect to an Ubuntu server through a mac terminal/console using ssh keys. It does not turn off the ability to login with a password (see step 7) and you cannot do this with root, see step 4.
Generate Mac keys. In terminal on your mac type:
ssh-keygen -t rsa -b 2048
Whilst still in terminal type:
nano /Users/YOURMACUSERNAME/.ssh/id_rsa.pub
Copy the text on the screen
SSH into your server and type
nano /home/YOURUBUNUTUSERNAME/.ssh/authorized_keys
The Ubuntu username could be anything (except root), you cannot login using this method and root. If you need to learn how to create a new user see my other tutorial How to disable root on Ubuntu.
Paste into here then press
press ctrl+x
type “Y” and press enter.
You may not need to do this depending on your Ubunutu setup
sudo nano /etc/ssh/sshd_config
Make sure the following lines are as follows:
RSAAuthentication yes
PubkeyAuthentication yes
Optional (Disable password login) In the same file as step 6 if you want to turn off the ability to login with a password change the following lines:
PasswordAuthentication no
UsePAM no