{ SSH. }

Objectives

By the end of this chapter, you should be able to:

  • set up an EC2 instance on Amazon
  • use the ssh command to connect securely to a remote server
  • use the scp command to copy files to a remote server

SSH

SSH, or Secure Shell, provides a secure channel to access other computers. We commonly use SSH to remotely log in and connect securely to other servers. To practice with SSH we will be setting up our own remote servers using Amazon EC2. This setup can be a bit intimidating, but it's a very valuable skill to know with any kind of development. Let's get started!

Setting up an EC2 Instance

As evidenced by the list below, there are a fair number of steps involved in setting up your instance. The links provided also provide a fair amount of context, and help explain the purpose of each of the following steps.

  1. Make sure that you have an Amazon Web Services (AWS) account. You can log in / sign up here and click on the top right.
  2. Create an IAM user here.
  3. Create a key pair here
  4. Create a VPC here
  5. Create a Security Group here
  6. Launch your instance here
  7. Connect to your instance here.

To connect to your instance using SSH you can start here.

Before you try to SSH make sure that your instance is running and that the checks have passed. This should involve typing something along the lines of ssh -i ./me-key-pair-uswest2.pem [email protected]_PUBLIC_DNS

Once you've connected via SSH, you can exit out of the shell by typing exit.

Securely copying files to the EC2 Instance with scp

To move files to your EC2 instance, we use the scp command to securely copy information. We will need our pem file that we used before so make sure you know where that is located. The pattern for scp looks like this:

scp -i PATH_TO_YOUR_PEM_FILE FILE_TO_MOVE [email protected]_DNS

This command would move the file move.txt from my current directory to the home directory on my EC2 instance.

scp -i ./me-key-pair-uswest2.pem move.txt [email protected]:/

Terminate your instance

When you are done working on this tutorial - you MUST terminate your instance so that it is not still running. This ensures that you will not be charged for anything as well. You can read more about it here

When you're ready, move on to Cut, Sed, Awk, and Xargs

Continue

Creative Commons License