Connect to a Remote Server with SSH (Beginner’s Guide)


Connect to a Remote Server with SSH
SSH (Secure Shell) is the most commonly used protocol to securely connect to remote servers. It allows you to execute commands, manage servers, and transfer files over an encrypted connection.In this tutorial, you’ll learn:
How to install and enable SSH
How to connect to a remote server
How to set up SSH keys for passwordless login
How to copy files securely using SCP
What is SSH?
SSH is a secure protocol that enables encrypted communication between a client and a remote server. It replaces insecure login methods like Telnet and is widely used in Linux servers, cloud instances, and DevOps workflows.
Check if SSH Is Installed
Run the following command on your server:sudo systemctl status sshdIf SSH is installed, you’ll see the service running.
Install and Enable SSH
Install SSH Server (Ubuntu / Debian)
sudo apt-get update
sudo apt-get install openssh-server -ypgsqlEnable and Start SSH
sudo systemctl enable ssh
sudo systemctl start sshVerify status:sudo systemctl status sshnsisConnect to a Remote Server Using SSH
Use the following command from your local machine:
ssh <username>@<ip-address>xml📌 Example:
ssh ubuntu@54.12.34.56nginxYou’ll be prompted to enter the remote server password.
⚠️ Password-based login is not recommended for production environments.
Why Use SSH Keys Instead of Passwords?
More secure than passwords
No need to enter password every time
Prevents brute-force attacks
Required for automation (CI/CD, Ansible, GitHub Actions)
Setting Up SSH Keys (Passwordless Login)
Step 1: Generate SSH Key on Local Machine
ssh-keygen -t rsa -b 4096 -C your-email@example.comcssPress Enter to accept default values.
This generates:
Private key: id_rsa
Public key: id_rsa.pub
Step 2: Copy Public Key to Remote Server (Recommended)
ssh-copy-id <remote-user>@<ip-address>vim📌 Example:
ssh-copy-id ubuntu@54.12.34.56applescriptNow try logging in again:
ssh ubuntu@54.12.34.56nginx✅ You should log in without a password.
Alternative Manual Method
If ssh-copy-id is unavailable:
Copy public key:
cat ~/.ssh/id_rsa.pubarcadeLog in to the remote server
Navigate to:
cd ~/.sshbashCreate or edit file:
nano authorized_keysebnfPaste the public key and save
Ensure permissions:
chmod 600 authorized_keys
chmod 700 ~/.sshbashDownload Files from Remote Server Using SCP
Once SSH is configured, you can securely copy files using SCP.
Syntax
scp <user>@<remote-ip>:<remote-file-path> <local-path>elixirExample
scp ubuntu@54.12.34.56:/home/ubuntu/app.log ~/Downloads/rubyThis downloads app.log from the remote server to your local machine.
Common SSH Use Cases
Server administration
Cloud instance access (AWS, Azure, GCP)
CI/CD deployments
File transfers
Automation and scripting
Conclusion
SSH is a fundamental skill for anyone working in Linux, Cloud, or DevOps. By setting up SSH keys, you significantly improve security and enable automation-friendly workflows.Now that you know how to:
Install SSH
Connect securely
Enable passwordless login
Transfer files
You’re ready to manage remote servers like a pro 🚀
👉 Check out my other blogs to learn more about DevOps and Cloud technologies. Thanks for reading!