0
0
Linux CLIscripting~5 mins

Why SSH enables secure remote management in Linux CLI - Why It Works

Choose your learning style9 modes available
Introduction
Managing a computer from far away can be risky if the connection is not safe. SSH helps by creating a secure tunnel so you can control another computer without others spying or messing with your commands.
When you want to fix or update a server located in a different building or city.
When you need to run commands on a remote computer without physically being there.
When you want to transfer files safely between your computer and a remote machine.
When you manage multiple computers and want to automate tasks remotely.
When you want to protect your login details and data from hackers during remote access.
Commands
This command connects you securely to the remote computer at example.com using the username 'user'. It starts a safe session where your commands run on the remote machine.
Terminal
ssh user@example.com
Expected OutputExpected
user@example.com's password:
This command creates a new pair of SSH keys (a secure way to log in without a password). The private key stays on your computer, and the public key can be shared with the remote server.
Terminal
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""
Expected OutputExpected
Generating public/private rsa key pair. Your identification has been saved in /home/user/.ssh/id_rsa. Your public key has been saved in /home/user/.ssh/id_rsa.pub. The key fingerprint is: SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX user@hostname The key's randomart image is: +---[RSA 4096]----+ | .o+o | | . +o. | | . + . | | o . | | S . | | | | | | | | | +----[SHA256]-----+
-t - Specifies the type of key to create (rsa).
-b - Sets the number of bits in the key (4096 for strong security).
-f - Defines the file name for the key.
-N - Sets an empty passphrase for the key.
This command copies your public SSH key to the remote server so you can log in without typing your password every time.
Terminal
ssh-copy-id user@example.com
Expected OutputExpected
Number of key(s) added: 1 Now try logging into the machine, with: "ssh user@example.com" and check to make sure that only the key(s) you wanted were added.
Now you connect to the remote server again, but this time it uses your SSH key for a secure, password-less login.
Terminal
ssh user@example.com
Expected OutputExpected
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-50-generic x86_64) user@example:~$
Key Concept

SSH creates a secure, encrypted connection that protects your commands and data when managing a remote computer.

Common Mistakes
Trying to connect without SSH installed on the remote server.
The connection will fail because the server cannot accept SSH connections.
Make sure the remote server has an SSH service running before connecting.
Not setting correct permissions on SSH key files.
SSH will refuse to use keys if permissions are too open, causing login failures.
Set private key permissions to 600 using 'chmod 600 ~/.ssh/id_rsa'.
Sharing private SSH keys instead of public keys.
Private keys must remain secret; sharing them compromises security.
Only copy the public key (~/.ssh/id_rsa.pub) to the remote server.
Summary
Use SSH to connect securely to remote computers and protect your data.
Generate SSH keys to enable password-less and safer logins.
Copy your public key to the remote server to avoid typing passwords every time.
Always check SSH service availability and file permissions for smooth connections.