CodingNic

Advanced Terminal Commands

SSH

Advanced Terminal Commands 15 min read

SSH

Objectives

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

  • Set up a remote server on Amazon EC2
  • Connect to it securely with ssh
  • Copy files to it with scp

⚠️ Before you start: this lesson uses a real Amazon Web Services (AWS) account, and a running EC2 instance can incur charges. Stick to the AWS free tier, and make sure you terminate your instance the moment you’re done — the last section covers exactly how.

💡 Why this matters: Almost all real-world development eventually touches a remote server — deploying an app, debugging something in production, configuring infrastructure. SSH is how you get onto that server securely in the first place.

What Is SSH?

SSH (Secure Shell) opens a secure, encrypted connection to another computer so you can operate it as if you were sitting in front of it. It’s the standard way developers log into remote servers. To actually practice it, you’ll set up your own throwaway server using Amazon EC2.

Setting Up an EC2 Instance

Roughly, the setup involves:

  1. Have an AWS account.
  2. Create an IAM user.
  3. Create a key pair.
  4. Create a VPC.
  5. Create a security group.
  6. Launch your instance.
  7. Connect to it.

AWS’s own console walks you through most of these with up-to-date screens, since the exact steps shift over time — treat this as the checklist, not a click-by-click script.

Before trying to connect, confirm your instance is running and has passed its status checks. Connecting looks like:

bash
ssh -i ./my-key-pair.pem ec2-user@YOUR_PUBLIC_DNS

YOUR_PUBLIC_DNS is the address AWS assigns your instance — you’ll find it in the EC2 console. Once you’re in, exit disconnects the SSH session.

Copying Files with scp

scp securely copies files to (or from) a remote server, using the same key pair you connected with. The shape:

bash
scp -i PATH_TO_YOUR_PEM_FILE FILE_TO_MOVE USERNAME@PUBLIC_DNS:DESTINATION

For example, this copies move.txt from your current directory to the home directory on the instance:

bash
scp -i ./my-key-pair.pem move.txt ec2-user@YOUR_PUBLIC_DNS:/

Cleaning Up

When you’re done, terminate your instance from the AWS console. This isn’t optional cleanup — leaving it running means it keeps costing money, whether or not you’re actively using it.

Try It

This one genuinely needs a real AWS account rather than a sandbox — if you have (or want to create) a free-tier account, work through:

  1. Launch an EC2 instance following the checklist above.
  2. Connect to it with ssh and run a couple of basic commands from earlier in this course (pwd, ls) to confirm you’re really on a different machine.
  3. Copy a small file to it with scp, then ssh back in and confirm it arrived.
  4. Terminate the instance.

Recap

  • SSH opens a secure remote connection; scp securely copies files over that same connection.
  • Both rely on the key pair you create when launching your EC2 instance.
  • Terminating an instance you’re not using isn’t optional — it’s what keeps this free.

Next lesson: cut, sed, awk, and xargs — the tools for processing text at scale instead of by hand.