Part 2: Mastering SSH and SCP for DevOps

In the previous post, we explored the basics of Linux. In this part, we’ll dive into two essential tools for DevOps engineers: SSH (Secure Shell) and SCP (Secure Copy Protocol). These are crucial for securely connecting to servers and transferring files.
What is SSH?
SSH (Secure Shell) is a protocol that allows secure access to remote servers, such as AWS EC2 instances. This is fundamental for managing remote servers in the DevOps workflow.
Connecting to a Server Using SSH
Here are the steps to connect to a server via SSH:
Locate the Key Files: Navigate to the directory where your
.pem
key file is stored.Install the
.pem
File: Ensure the.pem
file is installed on your system.Run the SSH Command: Use the following command to connect:
$ ssh -i pemfile user@serverip
pemfile
: The private key file for authentication.user
: The username for the server (e.g.,ubuntu
).serverip
: The IP address of the server.
This command securely establishes a connection to your server and is an indispensable tool in your DevOps journey.
Common SSH Commands
sudo
: Executes commands as an administrator.Example:
$ sudo apt-get update
Updates your Linux system.
Example:
$ sudo apt-get install docker
Installs Docker on your Linux system.
man ssh
: Displays the manual for the SSH command.
What is SCP?
SCP (Secure Copy Protocol) is a command used to securely transfer files between your local machine and a remote server.
Transferring Files to a Server
Steps to transfer a file from your local machine to the server:
Change Directory: Navigate to the directory containing your
.pem
key file:$ cd downloads/keys
Create a File: For example, create a file named
fromlocal.txt
:$ touch fromlocal.txt
Get Current Directory Path: Use the
pwd
command to find the present working directory:$ pwd
Run the SCP Command:
$ sudo scp -i pemfile fromlocal.txt user@serverip:/destination/path
Transferring Files from Server to Local
To copy a file from the server to your local machine, use the following command:
$ sudo scp -i pemfile user@serverip:/source/filename .
- The dot (
.
) indicates the current directory on your local machine as the destination.
Key Takeaways
SSH is critical for secure connections to remote servers.
SCP makes file transfers between your local machine and server secure and seamless.
Mastering these tools will enhance your ability to manage and automate server interactions as a DevOps engineer.
In the next post, we’ll delve into advanced server management and automation techniques. Stay tuned for more DevOps tips!
Subscribe to my newsletter
Read articles from Ansh Balan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Ansh Balan
Ansh Balan
I am a third-year BE CSE student with a strong enthusiasm for continuous learning and skill development. Proficient in C, C#, Java, JavaScript, Python, TensorFlow, DSA, and HTML, I have gained practical experience through various projects, including those utilizing Java Swing and AI technologies. My hands-on involvement in hackathons has further honed my problem-solving abilities and teamwork skills. I am eager to leverage my technical knowledge and project experience to contribute to innovative solutions and further my career in technology.