Ubuntu - Secure Shell
Ubuntu - Secure Shell (SSH)
Section titled “Ubuntu - Secure Shell (SSH)”Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution. SSH provides a secure channel for all communications between an SSH client and an SSH server.
1. Installing the OpenSSH Server on Ubuntu
Section titled “1. Installing the OpenSSH Server on Ubuntu”Most Ubuntu Desktop installations do not come with an SSH server pre-installed. Ubuntu Server installations usually include it. To install or ensure it’s present:
Step 1.1 − Update your package list:
sudo apt updateStep 1.2 − Install the OpenSSH server package:
sudo apt install openssh-serverStep 1.3 − Verify the SSH service is running:
sudo systemctl status sshYou should see ‘active (running)’. If not, you can start it with sudo systemctl start ssh and enable it to start on boot with sudo systemctl enable ssh.
2. Finding Your Ubuntu Machine’s IP Address
Section titled “2. Finding Your Ubuntu Machine’s IP Address”You’ll need the IP address of your Ubuntu machine to connect to it. On the Ubuntu machine, run one of the following commands in the terminal:
ip addr showLook for an entry like inet 192.168.1.10/24 under your active network interface (e.g., eth0 or wlpXsY). Alternatively, for a quicker view of just IP addresses:
hostname -IThis will usually show your primary IP address first.
3. Connecting from a Client Machine
Section titled “3. Connecting from a Client Machine”You can connect from various operating systems.
From Linux or macOS:
Section titled “From Linux or macOS:”Open a terminal and use the ssh command:
ssh username@your_ubuntu_ip_addressReplace username with your actual username on the Ubuntu machine and your_ubuntu_ip_address with its IP address (e.g., ssh john@192.168.1.10).
From Windows:
Section titled “From Windows:”Modern Windows (Windows 10 and later) includes a built-in OpenSSH client. You can open PowerShell or Command Prompt and use the same command as Linux/macOS:
ssh username@your_ubuntu_ip_addressAlternatively, you can use a third-party SSH client like PuTTY:
Step 3.1 (PuTTY) − Download PuTTY from its official website (putty.org).
Step 3.2 (PuTTY) − Launch PuTTY. In the ‘Host Name (or IP address)’ field, enter your Ubuntu machine’s IP address. Ensure ‘Port’ is set to 22 and ‘Connection type’ is ‘SSH’.
Step 3.3 (PuTTY) − Click ‘Open’.
First Connection and Authentication:
Section titled “First Connection and Authentication:”The first time you connect to a new server, you’ll likely see a message about the authenticity of the host:
The authenticity of host '192.168.1.10 (192.168.1.10)' can't be established.ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.Are you sure you want to continue connecting (yes/no/[fingerprint])?Type yes and press Enter. This saves the server’s public key fingerprint to your local machine’s known_hosts file, so you won’t be prompted again unless the server’s key changes.
Next, you’ll be prompted for your password on the Ubuntu machine. Enter it and press Enter.
If successful, you’ll be logged into your Ubuntu machine’s command line remotely.
4. Best Practice: SSH Key-Based Authentication
Section titled “4. Best Practice: SSH Key-Based Authentication”Password authentication is convenient but less secure than key-based authentication. SSH keys provide a more secure way of logging into a server without needing to enter a password.
Briefly, the process involves:
- Generating an SSH key pair (public and private keys) on your client machine (using
ssh-keygen). - Copying the public key to the
~/.ssh/authorized_keysfile on your Ubuntu server (usingssh-copy-id username@your_ubuntu_ip_address). - Configuring the SSH server (optional, but recommended for higher security) to disable password authentication once keys are set up.
This topic is more advanced but highly recommended for regular SSH users. You can find many tutorials online by searching for ‘SSH key authentication’.
SSH is a fundamental tool for managing Linux servers, enabling secure remote administration, file transfers (with scp or sftp), and tunneling.