0%

Install openssh-server on Ubuntu and ssh usage

Install openssh

Update first

1
sudo apt-get update -y

Install openssh-server

1
sudo apt install openssh-server -y

install-openssh-server

Usage

Check IP by

1
ifconfig

If you got this:

ifconfig

Install ifconfig by

1
sudo apt install net-tools -y

Or use the command to get your IP address

1
ip addr

And connect via

1
ssh <username>@<hostname>

Or

1
ssh <username>@<hostname> -p <port>

To using default 22 port to connect

connect-host-via-ssh

Enable ssh service start on boot:

1
sudo systemctl enable ssh

Let firewall allow ssh service

1
2
3
sudo ufw allow ssh
# or
sudo ufw allow 22

Allow root login

1
2
sudo vim /etc/ssh/sshd_config
# change "PermitRootLogin no" to "PermitRootLogin yes"

ssh keyless login

Create ssh rsa key on the computer you want to connect to host

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[neil@yimincai.net ~]$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/neil/.ssh/id_rsa): [Press enter key]
Created directory '/home/neil/.ssh'.
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Press enter key]
Your identification has been saved in /home/neil/.ssh/id_rsa.
Your public key has been saved in /home/neil/.ssh/id_rsa.pub.
The key fingerprint is:
1f:ad:49:00:4a:d5:ab:99:b3:b0:f9:09:91:c4:ed:d2 neil@yimincai.net
The key's randomart image is:
+--[ RSA 2048]----+
| ..oooE.++|
| o. o.. |
| .. . |
| o . . o|
| S . . + |
| . . . o|
| . o o ..|
| + + |
| +. |
+-----------------+

Create .ssh Directory on host server

1
2
3
4
5
6
7
[neil@yimincai.net ~]$ ssh alyssa@192.168.50.6 mkdir -p .ssh

The authenticity of host '192.168.50.6 (192.168.50.6)' can't be established.
RSA key fingerprint is 48:0e:28:11:d6:81:68:16:04:5f:db:49:02:la:12:4e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.50.6' (ECDSA) to the list of known hosts.
alyssa@192.168.50.6's password: [Enter Your Password Here]

Copy public key from local to host server

1
cat ~/.ssh/id_rsa.pub | ssh alyssa@192.168.50.6 'cat >> .ssh/authorized_keys'

On host server restart ssh service

1
service ssh restatus

On host server check ssh service status

1
service ssh status

ssh-status