What is SSH in Linux?
SSH means Secure Shell. It is a safe way to connect to another
computer over a network.
Why do we use SSH?
We use SSH to:
- Logging into a remote Linux server
- Run commands from far away
- Send and receive files safely (using
scporsftp) - Managing cloud servers (AWS, Azure, DigitalOcean, etc.)
- Setting up secure tunnels (port forwarding)
Does SSH Only Work on Linux?
No. SSH works on many operating systems.
✅ Linux
✅ Windows
✅ macOS
For example, you can use a Windows laptop to connect to a Linux server by opening PowerShell or Command Prompt and typing:
ssh alice@192.168.1.10
You can also connect from macOS to Linux. If Windows has an SSH server installed, you can even connect to a Windows computer using SSH.
This means SSH is a cross-platform tool that works on different operating systems.
Real-Life Example
One of the use case:
Imagine you are at home, but your office computer is turned on.
Without driving to the office, you can use SSH to connect to that
computer and do your work. It is like using a secure remote control for
your computer.
Installing SSH
To use SSH, you need to install the OpenSSH package. It provides both the SSH client and the SSH server.
On Ubuntu or Debian
sudo apt update
sudo apt install openssh-client openssh-server
To start the SSH service, use:
sudo systemctl start sshd
Note: If you see this error while starting the SSH service:
Failed to start sshd.service: Unit sshd.service not found.To fix this issue, see this guide: click here
To make the SSH service start automatically every time the computer boots:
sudo systemctl enable sshd
Check the SSH Service Status
To check if the SSH service is running, use:
sudo systemctl status sshd
If the service is running, you should see active (running) in the output.
Basic SSH Command
ssh username@server_ip
Example:
ssh alice@192.168.1.10
After connecting, you'll usually be prompted for a password (unless you're using SSH keys).
Example session
$ ssh alice@192.168.1.10
alice@192.168.1.10's password:
Welcome to Ubuntu!
alice@server:~$
Now you can run commands on the remote machine as if you were sitting in front of it.
SSH key authentication (optional)
Instead of using a password every time, you can use an SSH key pair.
- Generate a key:
ssh-keygen
- Copy the public key to the remote server:
ssh-copy-id username@hostname
- Then log in without entering a password:
ssh username@hostname
Some useful SSH options:
- Connect using a specific port:
ssh -p 2222 username@hostname
- Use a specific private key:
ssh -i ~/.ssh/my_key username@hostname
- Run a single command remotely:
ssh username@hostname "ls -l /home"
Secure file transfer
- Copy a file to a remote server:
scp file.txt username@hostname:/home/username/
- Copy a file from a remote server:
scp username@hostname:/home/username/file.txt
How SSH works
- The SSH client (your computer) connects to the SSH server (remote computer).
- They authenticate each other using a password or SSH keys.
- An encrypted connection is established.
- All commands and data are securely transmitted.
Why is SSH Safe?
✅ Can transfer files securely
✅ Supports password and key-based authentication
✅ Widely used on Linux and cloud servers
✅ SSH encrypts your data and communication. This means other people cannot easily read your passwords or commands while they travel over the internet.
Summary
SSH is a simple and secure tool for connecting to another
computer. It helps you work from anywhere while keeping your data safe.
Top comments (0)