Enabling ssh on ubuntu 18.04
The SSH protocol uses encryption to secure the connection between a client and a server.All user authentication, commands, output, and file transfers are encrypted to protect againest attacks in the network.On Ubuntu 18.04 LTS, the SSH server is called Openssh server. The openssh server program is available in the official package repository of Ubuntu 18.04 LTS.
prerequisites:
make sure you are logged in as a root user or any other user with sudo privileges.
Step 1: Enabling ssh on ubuntu
SSH server package is not installed on Ubuntu by default. ssh server package is available on standard Ubuntu repositories and it can be easily install with apt.
open the terminal with ctrl+Alt +t and install openssh like below.
sudo apt-get update
sudo apt-get install openssh-server
Now verify the SSH server package installation by running below command.
sudo systemctl status ssh
sample output:
install@ubuntu18:~# systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-06-17 09:34:52 UTC; 1h 13min ago
Process: 871 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 1042 (sshd)
Tasks: 1 (limit: 1670)
CGroup: /system.slice/ssh.service
└─1042 /usr/sbin/sshd -D
Jun 17 09:34:40 ubuntu18 systemd[1]: Starting OpenBSD Secure Shell server...
Jun 17 09:34:52 ubuntu18 sshd[1042]: Server listening on 0.0.0.0 port 22.
Jun 17 09:34:52 ubuntu18 sshd[1042]: Server listening on :: port 22.
Jun 17 09:34:52 ubuntu18 systemd[1]: Started OpenBSD Secure Shell server.
Step 2: Allow ssh in firewall
ubuntu comes with default firwall config tool known as ufw.if the firewall is running on your system, then make sure you need to open ssh port.
sudo ufw allow ssh
sudo ufw reload
Step 3: Access ubuntu system
you can access ubuntu machine from windows through putty.you need to find out ip address of your ubuntu machine with command "ifconfig" or "ip a"
install@ubuntu18:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:8e:18:b3 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.15/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 2401:4900:22a3:f157:a00:27ff:fe8e:18b3/64 scope global mngtmpaddr noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe8e:18b3/64 scope link
valid_lft forever preferred_lft forever
As per above sample output ip address is 192.168.0.15
Now open putty and give host name as ip address and give port as 22 and click on connect then it prompts for username and password.When you connect to the Ubuntu system for the first time, You may get a pop-up window to accept fingerprint.then click yes to connect it.
From linux machines you can connect with foloowing command
root@ubuntu18:~# ssh install@192.168.0.15
The authenticity of host '192.168.0.15 (192.168.0.15)' can't be established.
ECDSA key fingerprint is SHA256:eURbhGCiWj/sOYfQH5WZ6Ed3slwGaKbgVXGw+fxCRQw.
Are you sure you want to continue connecting (yes/no)?
click yes to connect it. then it prompts for password.once you entered the password then you can able to login and will get message like below.
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-88-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Wed Jun 17 11:15:02 UTC 2020
Step 4: Allow Root Access
By default root login over ssh is not allowed in ubuntu systems. you can enable it in ssh config file by editing the following command.
sudo nano /etc/ssh/sshd_config
Find out the line 'PermitRootLogin' and change it like below
PermitRootLogin Yes
save the file. Now restart ssh service with the following command.
sudo systemctl restart ssh
Now you are able to login ssh with root user directly.once you are logged and can run any command you want on your remote system from your local machine like below.
root@ubuntu18:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic
Step 5: Disable/Enable ssh service
if you want to stop/start ssh service, you can stop/start it with following command.
systemctl stop ssh
systemctl start ssh
if you want to ssh service to stop when your computer boots, then ssh service must be removed from the system startup with following command.
systemctl disable ssh
For start ssh service on systemc boot, you must add on system startup
systemctl enable ssh
Thats'it.Now you have learned How to enable and disable ssh service on Ubuntu