You need to generate the key on your local machine and send the public key to the server. Instead, you set up your private key on your Ubuntu server and added your public key to your Mac.
First off, you're going to want to delete your server's SSH key from
~/.ssh/authorized_keys, because your server shouldn't be able to SSH into your own computer.
To generate a key, simply run
ssh-keygen on your local computer. Unless you know what you're doing, you can simply keep all options as default. Be sure to enter a key passphrase - this will protect your SSH key from being stolen by encrypting it.
Sysadmin Tip: Use
ssh-keygen -b 4096 to build a longer (and more secure!) key.
Once you have your keypair generated, you'll need to upload your public key to the server you want to connect to. If you accepted the default options, your public key will be at
~/.ssh/id_rsa.pub. Take the contents of this file and append it to
~/.ssh/authorized_keys on the server.
Sysadmin Tip: Do not, under any circumstances, give anyone or anything your private half of the key. It's called the private key for a reason.
If your server is properly configured, this will be enough to allow you to sign in using your SSH key. However, your server may not be configured properly. Ensure you have the following three lines in your server's
/etc/ssh/sshd_config, and the lines are exactly as they appear here:
If these lines are not there, or they are not as they appear above, edit the file using
nano or similar. Note that you will need admin (
sudo) privileges to edit this file. If you did have to edit your config, you will need to restart your SSH service using
sudo systemctl restart ssh.service.
Sysadmin Tip: To increase security, you can disable password authentication on your server by changing
PasswordAuthentication line to
Depending on your server configuration, these steps may not be the most accurate. Contact your administrator if you have one. Instructions may be different depending on your platform or configuration -- also be sure to check any relevant documentation for your platform's alternatives to commands (e.g. PuttyGen instead of
ssh-keygen on Windows).
If this still doesn't work, you'll have to start delving into logs. Connect to your server using
ssh -vvv user@host, and look at the server SSH logs at