6
7
In debian kali I tried to connect ssh and getting the following error :
SSH: connect to host localhost port 22: Connection refused
Background :
I was trying to connect ssh in debian, I am using kali 2.0 sana
What I have tried/did:
`apt-get install openssh-server`
installed openssh-server and its uptodate
Queried service ssh status
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
Active: active (running) since Wed 2015-09-23 17:20:36 IST; 36min ago
Main PID: 1594 (sshd)
CGroup: /system.slice/ssh.service
└─1594 /usr/sbin/sshd -D
Reconfigured dpkg-reconfigure openssh-server and it also lead to success
Now I tried to connect ssh root@localhost
which requires root@localhost password so what I did was
vi /etc/ssh/sshd_config
and added command to deny root login :
My sshd_config as follows :
What ports, IPs and protocols we listen for Port 22
#Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0 Protocol 2
# 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
#Privilege Separation is turned on for security UsePrivilegeSeparation yes
Now again tried to connect ssh via ´ssh root@localhost´ not I got connect to host localhost port 22: Connection refused
I though my iptables
might be preventing it so configured it as :
vim /root/firewall.rules
root@vignesh:~# iptables-save > /root/firewall.rules
root@vignesh:~# iptables -X
root@vignesh:~# iptables -t nat -F
root@vignesh:~# iptables -t nat -X
root@vignesh:~# iptables -t mangle -F
root@vignesh:~# iptables -t mangle -X
root@vignesh:~# iptables -P INPUT ACCEPT
root@vignesh:~# iptables -P FORWARD ACCEPT
root@vignesh:~# iptables -P OUTPUT ACCEPT
root@vignesh:~# iptables-save > /root/firewall.rules
And I queried the iptables-save
# Generated by iptables-save v1.4.21 on Wed Sep 23 18:50:34 2015
*mangle
:PREROUTING ACCEPT [41217:4171959]
:INPUT ACCEPT [27727:3255690]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1834:219528]
:POSTROUTING ACCEPT [1835:219654]
COMMIT
# Completed on Wed Sep 23 18:50:34 2015
# Generated by iptables-save v1.4.21 on Wed Sep 23 18:50:34 2015
*nat
:PREROUTING ACCEPT [15456:1179155]
:INPUT ACCEPT [1858:255303]
:OUTPUT ACCEPT [223:14078]
:POSTROUTING ACCEPT [223:14078]
COMMIT
# Completed on Wed Sep 23 18:50:34 2015
# Generated by iptables-save v1.4.21 on Wed Sep 23 18:50:34 2015
*filter
:INPUT ACCEPT [26756:3173280]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1775:215770]
COMMIT
As per comment checked
root@vignesh:~# netstat -an | grep 22
tcp 0 0 10.100.8.40:54036 216.58.220.46:80 ESTABLISHED
tcp 0 0 10.100.8.40:41573 216.58.220.14:80 ESTABLISHED
unix 3 [ ] STREAM CONNECTED 17722 @/tmp/dbus-JUNz9GwSon
unix 3 [ ] STREAM CONNECTED 13422
unix 3 [ ] STREAM CONNECTED 17224
unix 3 [ ] STREAM CONNECTED 17422
unix 2 [ ] DGRAM 9222
unix 3 [ ] STREAM CONNECTED 17221 /var/run/NetworkManager/private
unix 3 [ ] STREAM CONNECTED 17225 /var/run/NetworkManager/private
unix 3 [ ] STREAM CONNECTED 17229
unix 3 [ ] STREAM CONNECTED 17220
Now again I tried ssh root@localhost
but again got the error.
Kindly guide me where I am missing the part? How can I get it connected?
Do you mind trying with a non-root user and telling what happens? Also is your sshd file just those lines? Try to add: "PermitRootLogin yes" – SOMN – 2015-09-23T13:58:10.290
Could you run "netstat -an | grep 22" and edit your question to include the output? – Kenster – 2015-09-23T14:10:23.723
@Glaudio yes bro i already tried it but connection refused for the same – BlueBerry - Vignesh4303 – 2015-09-24T03:44:06.153
@kenster added output of it bro – BlueBerry - Vignesh4303 – 2015-09-24T03:46:50.690
Your post shows garbage in your
sshd_config
file. – David Schwartz – 2015-09-30T13:18:50.913@DavidSchwartz sorry friend completely noob at this stuff,what do u mean by garbage in my sshd_config file ,what i need to do if i find garbage over there,how can i resolve it friend :) – BlueBerry - Vignesh4303 – 2015-09-30T13:21:34.473
2Look at your own post. Look at the beginning of the
sshd_config
. Maybe that's not really in the file, but if it is, that's a problem. – David Schwartz – 2015-09-30T13:22:18.447Is your entire sshd_config commented out? Here is an example of what it should look like (your data above has all the line jumbled together):
https://gist.github.com/wwalker/089b22fce0fd962f1d50
You show the commentary uncommented and the directives commented out.
The file looks terrible, if that is just a pasting error, and the file is good, then try this and post it here:
My guess is that it is listening on a different port.