SSH Access to Servers (Mac and Windows)

  • !! Remember your backend code might be running in a docker container, so you won’t see the code directly on the instance – you have to look into the docker container
    • To see running docker instances: sudo docker ps -a
  • To ssh direct into instance, you can use a pem file
  • To copy files, see Copying Files From an SSH-ed Instance
  • Ssh access: These are the commands to run on command line:
    • !! It’s not the same on Windows – see below
    • This: ssh -i "your-pem-file.pem" ubuntu@[ip address here]
    • Your pem file has to be in same path - or specify exact path
    • To find the url: Go to EC2 instance, select in EC2, bottom right see public IPv4 and domain IPv4 - one is just numbers, one is longer with letters, either one of those will do
    • Note that each url must be prefixed by user name
      • For instances which are spawned by EBS, the user is likely to be ec2-user
    • To ssh out again, type logout
  • !!On Windows, use Putty.

Copying Files From an SSH-ed Instance

  • To copy files, use SCP command or PSCP on Windows with Putty installed (see above)
    • SCP on a Mac:
      • scp -i "[path to file]" ubuntu@[ip address]:/home/ubuntu
      • !! Note that you might only have permission to copy into home folder
      • That command (^) copies files from local machine to ssh-ed machine
      • To do it the other way around, just swap source and target
    • PSCP in Windows with PuTTY:
      • Copying files from the ssh-ed machine to the outside world:
        • First create a saved host config:
          • In PuTTY, set up a host config
          • Then instead of clicking Open, select Sessions (top left)
          • Enter a name under Saved Sessions
          • Click Save
          • Now if you want that host config again, you can just click Load
        • Now in a command prompt: pscp ec2-user@SavedHost:/folder/myfile.txt C:\Temp
          • (or pscp C:\Temp/myfile.txt ec2-user@SavedHost:/folder for the opposite direction)
          • SavedHost is your saved PuTTY host config.
          • In this case ec2-user is the user you are using to log in to the remote server
          • This will copy the file from the remote SSH-ed host to your local machine.
        • More here:

PuTTy Tips

  • You can configure the user name (eg ec2-user) so you don't have to type it in every time - on the left, Connection | Data and then Auto-login username. Don't forget to go back to Session (left) and click Save.
  • When you make changes to a config, you have to go back to Session (top left) and click Save for those changes to stick.
  • You can use SSH tunnel (on the left - Connection | SSH | Tunnels) to attach a port to an SSH configuration and forward from that port to your server via SSH (you have to manually open the session first for it to work).

Copying files between a remote AWS SSM instance and your local machine