Enabling SSH on Ubuntu

234

Introduction

SSH (Secure Shell) is a network protocol that provides a secure way to connect to and control remote computers over a secure network. It allows users to create a secure, encrypted connection between their local computer and a remote server, enabling them to safely run commands, transfer data, and perform various administrative tasks.

Prerequisites

  • A system with the Ubuntu operating system installed and fully updated.
  • A stable internet connection.

Step 1: Install OpenSSH Server in Ubuntu

  1. Update the repository cache using the following command:

$ sudo apt update

2. Install the OpenSSH server by executing the following command:

$ sudo apt install openssh-server

Step 2: Configuring OpenSSH Server

$ sudo nano /etc/ssh/sshd_config

There are several parameters that you can modify in the SSH configuration file:

  • Port: To improve security, change the standard SSH port (22).
  • PermitRootLogin: This determines whether to enable or disable root SSH login.
  • PasswordAuthentication: Activate or deactivate password-based authentication.

To apply a setting, uncomment the line and change its value from yes or no respectively.

Save the changes and close the text editor by pressing Ctrl+O, then Enter, and finally Ctrl+X.

Restart the SSH service for the modifications to take effect and check the SSH status:

$ sudo systemctl restart ssh
$ sudo systemctl enable ssh
$ sudo systemctl status ssh

Step 3: Install OpenSSH Client in Remote Linux

Install the OpenSSH client package, which is used to establish secure encrypted connections to remote servers:

$ sudo apt install openssh-client

Open a terminal on a client machine and attempt to connect to your Ubuntu server using SSH. Replace your_username with your Ubuntu username and your_server_ip with the IP address of your Ubuntu machine/server:

$ ssh [email protected]_server_ip

Step 4: SSH Into Ubuntu Without a Password

On the client machine, open a terminal and generate an SSH key pair by running the command. Press Enter for default settings or specify your own values:

$ ssh-keygen -t rsa -b 4096

Copy the public key to the remote machine using the command with the same username and IP:

$ ssh-copy-id [email protected]

Now, when you try to connect to your Ubuntu remote machine, it will not prompt you for a password and you will directly get logged in. This is because you are authenticated using the private key on the client machine:

$ ssh [email protected]

By following these steps, you can enable SSH on your Ubuntu machine, allowing secure remote server management. This includes installing and configuring the OpenSSH Server, restarting and testing the SSH service, configuring SSH keys for authentication, and optionally disabling password-based authentication.