I recently tried to SSH into my server (an internet linking ham radio node) I just got back on air.

I typed ssh root@ which is my computers address confirmed by ifconfig eth0

Connection Refused of course comes up.

I had this problem before, I fixed it by finding the RIGHT IP by running ifconfig. I ran it now, and I had the right LAN IP

Here are the steps of what I did

•I set the IP to the MAC address of the computer on my router configuration, in my case

•I ran ifconfig eth0 and it showed up as on the screen.

•I forwarded all of the ports (although that is not necessary for LAN communication)

•I changed it from 222 to 22 in the /etc/ssh/sshd_config

•I rebooted the computer several times

•SSH works in reverse so if I type SSH then I can login to my own computer from the CentOS server computer

Attached are screenshots of my routers configuration.

enter image description here enter image description here enter image description here

ps aux |grep sshd


root 2923 0.0 0.0 4032 692 tty1        S+ 07:15 0:00 grep sshd


i#  $OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

Port 22
#Protocol 2,1
Protocol 2
#AddressFamily any
#ListenAddress ::

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication mechanism. 
# Depending on your PAM configuration, this may bypass the setting of 
# PasswordAuthentication, PermitEmptyPasswords, and 
# "PermitRootLogin without-password". If you just want the PAM account and 
# session checks to run without PAM authentication, then enable this but set 
# ChallengeResponseAuthentication=no
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner /some/path

# override default of no subsystems
Subsystem   sftp    /usr/libexec/openssh/sftp-server

UPDATE I ran service SSHD start, and got an error

Starting sshd: /etc/ssh/sshd_config: line 1: bad configuration option: i / etc/ssh/sshd_config: terminating, 1 bad configuration options [FAILED]

  • Is that ps being run on the CentOS server ? – Lawrence Jul 2 '14 at 13:43

Dumb me, found the problem. I had a character right before the first comment in the SSHD_Config, an "i" as can be seen in my config file.

enter image description here

Yayy it works

  • 1
    New to vim as well I suppose. – Bruno9779 Jul 2 '14 at 14:06
  • Yup, the I is from when I used the i key to go to edit mode, I typed I one to many times – Skyler 440 Jul 2 '14 at 14:07

There is more that just the port setting in /etc/ssh/sshd_config.

For example, the field AllowUsers, could limit your usage of sshd.

Read the man page for sshd_config:

man sshd_config

If you still cannot make sense of it post your entire /etc/ssh/sshd_config

  • Ok, im a newbie to this so I just will post the whole sshd_config – Skyler 440 Jul 2 '14 at 13:55

According to ps, ssh isn't even running, which would result in connection refused errors.

If you start the ssh daemon with service sshd start it should start up and you should be able to ssh to your server.

  • Uh Oh service sshd start returned an error. Look at the bottom of the question, I edited and posted the error – Skyler 440 Jul 2 '14 at 14:04
  • Oh found the problem. I hate dumb errors like that :-) the First line of the sshd config looked like this i#, removed the i and everything worked out perfect – Skyler 440 Jul 2 '14 at 14:04

Today(01-27-2016), I faced with the same issue! I wanted to ssh to a host as root, but was denied. I scoured the web and tried with many suggestions there, with out any success. Then I created new user "xyz" and tried to ssh as "xyz" and I could! That made me realize that sshd was not the issue, may be root ONLY has this problem. Hence, I checked my /etc/ssh/sshd_config file and noticed that "PermitRootLogin" was set to "no". I commented that out and restarted "sshd".

[root@yav-031 ~]# cat /etc/ssh/sshd_config|grep -i permit
#PermitRootLogin yes
#PermitEmptyPasswords no
# the setting of "PermitRootLogin without-password".
#PermitUserEnvironment no
#PermitTunnel no
#PermitRootLogin no <----------In my case this was NOT commented out 
[root@yav-031 ~]# 
# service sshd restart 

Then retried to login as root and I could login successfully!!! This site helped me think in 'right direction' and hence I thought to share with you and hence this note. Regards, -Deb

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.