User Tools

Site Tools


creating_an_ssh_shortcut

Link to this comparison view

Next revision
Previous revision
creating_an_ssh_shortcut [2019/06/26 10:07]
nmckillop created
creating_an_ssh_shortcut [2019/07/19 14:24]
ed [Using SSH keys on Linux/macOS]
Line 1: Line 1:
-====== ​Creating an SSH shortcut ​on Linux/macOS ======+====== ​Using SSH keys on Linux/macOS ======
  
-This is mostly for convenience ​but may be necessary if you are having problems using sshfs.+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>
  
-Rather than having to type something like: +Now you can SSH in with 
-<code>ssh -i .ssh/​myidentityfile.pem ubuntu@my_ec2_ip</​code>+  ​ssh ​<user@IP>
  
-You can create ssh shortcuts to simplify this to the following:​ +Optionally you can also create ​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:
-<​code>​ssh myec2</​code>​ +
- +
-To do so, create the file ''​.ssh/​config''​ (if it doesn'​t already exist) using this template:+
 <​code>​ <​code>​
-Host your_shortcut_name_here +Host <​shortname>​ 
-    HostName ​     your_ec2_ip_address_here +    HostName ​     ​<your_ec2_ip_address_here> 
-    IdentityFile  ​/​home/​ubuntu/.ssh/myidentityfile.pem+    IdentityFile  ​<~/.ssh/youridentityfile.pem>
     User          ubuntu     User          ubuntu
 </​code>​ </​code>​
 +
 +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 [[https://​code.visualstudio.com/​docs/​remote/​troubleshooting#​_local-ssh-file-and-folder-permissions|info about permissions here]]
 +
 +
creating_an_ssh_shortcut.txt · Last modified: 2019/07/19 14:24 by ed