How to Config SSH Server on Ubuntu
Ubuntu SSH Server Configuration
1. Environment
Server:
|
|
Client: Macbook Pro
2. Install Open SSH Server
Check ssh client (installed by default on Ubuntu 18.04 TLS)
|
|
Install SSH server
|
|
Then check installation.
|
|
Check process.
|
|
3. Configure ssh daemon
Change /etc/ssh/sshd_config
.
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
PermitEmptyPasswords no
- PermitRootLogin: “no” for prohibiting SSH root login.
- PubkeyAuthentication: “yes” for permitting SSH public key authentication
- PasswordAuthentication: “no” for prohibiting password authentication
- PermitEmptyPasswords: “no” for prohibiting blank password when turn on password authentication
4. Open ports
Ubuntu 18.04 LTS closes ports by default. Using utf(Uncomplicated FireWall), open the port for SSH.
|
|
5. Set static IP address
Ubuntu 18.04 supports network configuration at yaml files at /etc/netplan/
. (ex. /etc/netplan/01-network-manager-all.yaml
).
Define ethernets
section at 01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
enp3s0:
addresses: [192.168.0.18/24, 'xxxx:3b:xxxx:2:xxxx:xxxx:xxxx:xxxx/64'] # Mac address is on `ifconfig -a`
gateway4: 192.168.0.1
nameservers:
addresses: [192.168.0.1, 8.8.8.8, 8.8.4.4]
For checking network configuration, I installed net-tools
and run ifconfig -a
.
Apply updated configuration.
|
|
6. Configure SSH key
6.1. Server
At server, generate SSH key.
|
|
I setup pass phrase for SSH key file this time.
6.2. Client
6.2.1. authorized_keys
Then sent a public key (id_rsa_xxx.pub) to client and add that to ${HOME}/.ssh/authorized_keys
|
|
6.2.2. .ssh/config
Add server host to ~/.ssh/config
Host 92.168.0.18
Hostname ubuntu01
User xxxx
Port 22
IdentityFile ~/.ssh/id_rsa_xxx_202105
Then I could login to server to client by:
|
|