
I tried to connect Linux server.
But connection was refused.
Linux is common for server usage.
In initial settings of Linux server like Ubuntu, sometimes you fail SSH connection.
Why did it refuse connection ? What should we do to connect Linux server ?
So today, I will introduce about "What you should check when SSH connection is refused in Linux".
"connection refused" error


First, what is "connection refused" error ?
When you try to connect to Linux by SSH application like Tera Term, you would see "connection refused".
According to the message, it seems like below.
The server exists. But it didn't allow your connection.
What you should check when SSH connection is refused in Linux


So what should we check when SSH connection is refused in Linux?
There are some points to check.
About server side, we can check following points.
- SSH service software
- Service is working or not
- Server IP is known in the network or not
- Accsess from outside is allowed or not
- FW allows access or not
And we can check client side too.
- Network path from client to server
So I will explain each of them.
SSH service software


There is a software openssh-server
, you can install it by apt-get install
.
$ sudo apt-get install openssh-server
After installation, you can execute below.
Activate SSH on Ubuntu 14.04 – wide_snow’s blog
$ ssh -V
Then you can see the result. So installation is done correctly.
OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6, OpenSSL 1.0.1f6 Jan 2014
Service is working or not


In order to check openssh-server
is working or not, You can try SSH connection from the server to the server itself.
If you could login, openssh-server
is working.
$ ssh (IP address of server)
Server IP is known in the network or not


You can check IP address of server by ifconfig
command.
You can use ip a
command too.
But ifconfig
command can't prove that IP is known in the network or not.
If other machine uses same IP address, IP address conflict happens on network.
Then you can use nmap
command and check MAC address of IP that network(LAN) knows.
First you can activate nmap
by apt install
.
sudo apt install nmap
Then you check MAC address of IP on network.
In below case, network is 192.168.0.xxx.
$ sudo nmap 192.168.0.0/24 -sP
If MAC address that nmap
shows is not same as the MAC address that you checked by ifconfig
, it means that there is IP address conflict.
Access from outside is allowed or not


You can check access denied list in /etc/hosts.deny
.
If client access is denied in the list, you can comment or delete it.
$ sudo nano /etc/hosts.deny
$ sudo reboot
FW allows access or not


You can check FW allows access or not by ufw status
command.
$ sudo ufw status
If port 22 is not allowed, you can allow it.
$ sudo ufw allow ssh
Network path from client to server


With using ping
command, you can check that network path runs from client to server.
If response comes, network path is OK.
$ ping (IP address of server)
Conclusion


Today, I explained about "What you should check when SSH connection is refused in Linux".
In case of connection refused, we can check following things.
Server side
- SSH service software
- Service is working or not
- Server IP is known in the network or not
- Accsess from outside is allowed or not
- FW allows access or not
Client side
- Network path from client to server



If SSH connection is refused, we can check SSH software, network path, IP address conflict.