SSH :connect to host localhost port 22: Connection refused
Your netstat
output shows that there's no process listening to port 22
, and that would explain why you get a Connection refused
when trying to SSH.
Your status
info about the sshd
daemon shows running, however no listening port is associated with it (or doesn't seem to).
Further, as you were told in the comments, your sshd_config
file seem to be incorrect. You say you want to disable root login, so I'll propose a configuration for your SSH daemon.
Edit the /etc/ssh/sshd_config
file and put the following content in it:
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin no
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
ClientAliveInterval 30
ClientAliveCountMax 99999
If you're worried about security, you can restrict SSH only to the users you want. For example, if you want to restrict that only user vignesh
can SSH, you can add another directive like this:
AllowUsers vignesh
After that, simply restart the sshd
service. Once done, if you run netstat -atpn | grep 22
you should see the port 22
listening for everybody.
I can't see if you actually added this line, or uncommented it: Port 22
If no port is specified in sshd_config, sshd will not listen on any port. Given your output from netstat, this is likely the issue.
First of make sure your root account has set up with password
if root has no password you can sudo passwd root
then type new password for root.
Then you can SSH in with the -v
option for verbose output.:
ssh root@localhost -v
If the connection is still refused, please post the output of the ssh root@localhost -v
command.