I have installed the ssh utility on an embedded system but I can't connect to it. I am able to ssh from the device to another computer on the network but not the other way around.
The only port opened in the device is the 21st:
userk@dopamine:~$ nmap 160.80.97.X
Starting Nmap 6.40 ( http://nmap.org ) at 2015-02-09 20:49 CET
Nmap scan report for 160.80.97.X
Host is up (0.0092s latency).
Not shown: 999 closed ports
PORT STATE SERVICE
21/tcp open ftp
When I try to connect to it I get a connection refused error. I have tried with another port but nothing has changed. The configuration file /etc/ssh/sshd_config is the following
#Port 22
Port 223
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
# The default requires explicit activation of protocol 1
Protocol 2
# 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
HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 1h
ServerKeyBits 1024
# Ciphers and keying
#RekeyLimit default none
# Logging
# obsoletes QuietMode and FascistLogging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
MaxAuthTries 6
#MaxSessions 10
RSAAuthentication yes
PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
I don't have iptables and I can't install it. How can I connect to the device using ssh?
Solution
There was a problem with the generated keys. Move them to the /tmp folder
mv /etc/ssh/ssh_host_* /tmp
And regenerate the keys with
/etc/init.d/S50sshd restart OR /etc/init.d/sshd restart
or
ssh-keygen -A
Thanks to Bratchley, Abrixas2 and 0xC0000022L.
sshd
is actually running?netstat -tlpn
to see ifsshd
is both running and listening on the port you're expecting it to run on.mv /etc/ssh/ssh_host_* /tmp
and try to run/etc/init.d/sshd restart
and see if it regenerates the keys for you that way.ssh-keygen -A
to generate host keys for all known key types, for which host keys do not exist. This should normally be done during the configuration ofsshd
or during the first start ofsshd
.lsof -i TCP:22 -s TCP:LISTEN
say? Did you try to reinstall (apt-get --reinstall openssh-server
)sshd
or set it to start by default (update-rc.d ssh defaults
) and then start (withservice
)? All assuming Rasbian. Also, did you try to run the SSH server from the command line using$(which sshd) -Ddp 10222
(as superuser) and then connecting to port 10222 from a client? Ifsshd
isn't running you can also leave out the-p 10222
altogether. What aboutdpkg-reconfigure openssh-server
to regenerate all the host keys?