User Tools

Site Tools


Using SSH keys on Linux/macOS

Mac and Linux systems have builtin OpenSSH tools to connect to your server. It is fine to use the command ssh -i </path/key.pem> <user@IP> , but you can avoid typing it every time by adding the key to the authorisation agent:

ssh-add <key>

Now you can SSH in with

ssh <user@IP>

Optionally you can also create a ssh shortcut to avoid typing the username and IP. To do so, create the file ~/.ssh/config on your Mac (if it doesn't already exist) using this template:

Host <shortname>
    HostName      <your_ec2_ip_address_here>
    IdentityFile  <~/.ssh/youridentityfile.pem>
    User          ubuntu

Now you can SSH in with

ssh <shortname>

Other tips

To check what keys are added

ssh-add -l

If you want, you can view your server’s public key which was created and stored when it was set up

less .ssh/authorized_keys

If you get errors about permissions when trying to SSH in, you may have to modify the key file’s permissions with chmod

chmod 600 <file>

Check a file’s permissions with the longform list command

ls -l

See output like -r——–@ 1 user staff 1696 11 Jun 19:14 /path/yourfile.pem
Basically the first ten characters before the “@” indicate permissions and you want to see only dashes or “r” after the fourth character. man chmod has more.
More info about permissions here

creating_an_ssh_shortcut.txt · Last modified: 2019/07/19 14:24 by ed