How to set up SSH on Ubuntu 18.04

SSH, also known as Secure Shell or Secure Socket Shell, is a network protocol that gives users, particularly system administrators, a secure way to access a computer over an unsecured network. SSH also refers to the suite of utilities that implement the SSH protocol.

Here are the commands used to connect by Secure SHell:

On the server side

sudo apt-get install ssh

sudo apt-get install openssh-server

sudo /etc/init.d/ssh start

sudo nano /etc/ssh/sshd_config

Uncomment port 22
Uncomment HostKey /etc/ssh/ssh_host_rsa_key
Uncomment AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
Set pubkey authentication to "yes"

sudo systemctl restart sshd.service # or sudo /etc/init.d/ssh reload


On the client side:
in ~/.ssh

ssh-keygen -t rsa # set passphrase or not
ssh-copy-id -i ~/.ssh/id_rsa user@100.100.10.100

--> write "yes" then password in


ssh user@100.100.10.100

--> write password --> you should be in

--> in /home/user/.ssh/config type:
Host WhateverName
HostName 100.100.10.100
User username
ForwardX11 yes
ForwardAgent yes
IdentityFile ~/.ssh/id_rsa

--> you should now be able to connect with :

ssh WhateverName

Comments

  • LEGE 1788 days ago

    The SSH server is not installed by default on Ubuntu desktop systems but it can be easily installed from the standard Ubuntu repositories.

    To install and enable SSH on your Ubuntu system complete the following steps:

    Open your terminal either by using the Ctrl+Alt+T keyboard shortcut or by clicking on the terminal icon and install the openssh-server package by typing:

    sudo apt update

    sudo apt install openssh-server

    Once the installation is completed, the SSH service will start automatically. To verify that the installation was successful and SSH service is running type the following command which will print the SSH server status:

    sudo systemctl status ssh

    Ubuntu comes with a firewall configuration tool called UFW. If the firewall is enabled on your system, make sure to open the SSH port:

    sudo ufw allow ssh

    Once you’ve found the IP address, login to remote machine by running the following ssh command:

    ssh user@ip

    If you don’t know your IP address you can easily find it using the this

    ip a