Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a VM installed with some custom disk image (CentOS) from work, and I can't SSH into the VM.

Here are some things I've tried:

[VM]$ ssh root@localhost
Password:

Great, ssh is working with the loopback.

But when I try from the host machine:

~/VirtualBox VMs% ssh -v -v -v root@192.168.56.1
OpenSSH_5.9p1, OpenSSL 0.9.8y 5 Feb 2013
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.56.1 [192.168.56.1] port 22.
debug1: connect to address 192.168.56.1 port 22: Connection refused
ssh: connect to host 192.168.56.1 port 22: Connection refused

Nada. Ping works though.

on the VM, /etc/hosts.allow:

ssh:ALL:allow
sshd:ALL:allow

nothing in hosts.deny

EDIT:
I've also done:

service iptables save
service iptables stop
chkconfig iptables off

EDIT:
I'm also seeing this message on the VM in /var/log/secure
bind to port conflict
But I can ssh just fine from the VM to the VM, so this isn't the issue, right?

EDIT: [VM]$ lsof -i :22 lsof -i :22 output

And I have, in /etc/ssh/sshd_config

PermitRootLogin yes  

And cannot login with a separate username.

EDIT:
netstat -pant |grep :22 and netstat -ntp |grep :22 netstat -pant and netstat -ntp
I think maybe this also points towards the IPv6 solution?

EDIT:
Existing config for vi /etc/sysctl.conf /etc/sysctl.conf

New config for vi /etc/sysctl.conf /etc/sysctl.conf after change I then ran the commands:

sysctl -w net.ipv6.conf.default.disable_ipv6=1
sysctl -w net.ipv6.conf.all.disable_ipv6=1
chkconfig ip6tables off
service sshd restart
init 6

Aaaaaaand, still nothing. But after a restart, it looks like ipv6 isn't disabled. I'm getting the same error message. cannot bind port 22 And lsof -i :22 is still saying type IPv6: lsof -i :22

EDIT: Going further down the IPv6 rabbit hole.
http://ubuntu-tutorials.com/2008/01/12/disabling-ssh-connections-on-ipv6/
It says to remove the commented line with #ListenAddress ::, which seems fishy, cause it's already commented out. So I did, and nothing.

However, the next section has a useful tidbit: AddressFamily inet # IPv4 only When I add this line to /etc/ssh/sshd_config and do a couple consecutive restarts, I now see that my address binding error has stopped appearing in /var/log/secure /var/log/secure
and the output of lsof -i :22 now shows a type of IPv4! yay, progress! lsof -i :22 shows IPv4 Progress!! But unfortunately I still cannot connect. I tried rebooting the VM, opening new shell windows just in case there was some state left hanging around. Still the same answer.

~% ssh -vvv root@192.168.56.1
OpenSSH_5.9p1, OpenSSL 0.9.8y 5 Feb 2013
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.56.1 [192.168.56.1] port 22.
debug1: connect to address 192.168.56.1 port 22: Connection refused
ssh: connect to host 192.168.56.1 port 22: Connection refused

EDIT:
ok, so i got arp-scan and am trying to find IP conflicts, but now i'm even more confused. ifconfig shows that vboxnet0, which is the host-only adapter, has an IP of 192.168.56.1. That's where I got that IP to begin with.

[local]~root# ifconfig  
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 7c:d1:c3:e8:b0:e9 
    inet6 fe80::7ed1:c3ff:fee8:b0e9%en0 prefixlen 64 scopeid 0x4 
    inet 10.6.12.46 netmask 0xfffffe00 broadcast 10.6.13.255
    media: autoselect
    status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
    ether 0e:d1:c3:e8:b0:e9 
    media: autoselect
    status: inactive
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 0a:00:27:00:00:00 
    inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255
vboxnet1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 0a:00:27:00:00:01 
    inet 192.168.57.1 netmask 0xffffff00 broadcast 192.168.57.255

But arp-scan -l gives only domains starting with 10.6.*.*
So I guess it's looking at en0? So I tried
arp-scan -I vboxnet0 -l

mba-108-on-03:~ root# arp-scan -I vboxnet0 -l
Interface: vboxnet0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.56.100  08:00:27:bc:ed:2f   CADMUS COMPUTER SYSTEMS

512 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.8: 256 hosts scanned in 1.301 seconds (196.77 hosts/sec). 1 responded

Why is it now .100? #confused

vboxnet1 has nothing

mba-108-on-03:~ root# arp-scan -I vboxnet1 -l
Interface: vboxnet1, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)

512 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.8: 256 hosts scanned in 1.302 seconds (196.62 hosts/sec). 0 responded

All of the other interfaces don't work with arp-scan.

So let's show duplicates on the en0 interface:

mba-108-on-03:~ root# arp-scan -I en0 -l |grep DUP
10.6.12.68  84:8e:0c:75:5b:f4   (Unknown) (DUP: 2)
10.6.12.64  ac:cf:5c:42:24:47   (Unknown) (DUP: 2)
10.6.12.76  88:53:95:6e:6a:af   (Unknown) (DUP: 2)

These numbers don't correspond to anything meaningful for me. Going to try a reboot, then the IPv6 suggestion.

EDIT:
The VM is a VirtualBox.
Adapter 1: NAT
Adapter 2: Host-only Adapter, 'vboxnet0' config of adapter1 config of adapter2
Any ideas?

share|improve this question
    
answer at askubuntu.com/questions/30080/… might help –  Ketan Feb 6 at 4:41
    
Try attached to bridge –  Kevin Feb 6 at 4:42
    
using "Bridged Adapter" gets the same result –  Ken Feb 6 at 4:46
2  
What is the output of lsof -i :22? –  Chris Down Feb 6 at 5:13
    
Look like ip conflict –  SHW Feb 6 at 5:42

3 Answers 3

It looks like the ssh daemon is using IPv6 (from the output of lsof -i :22) while you are trying to connect with IPv4. The system won't know how to route the traffic.

I am not sure about the IP conflict you are seeing, but would suggest trying the following:

  1. Disable IPv6

    Add the following to /etc/sysctl.conf

    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    

    Disable IPv6 on the running system

    sysctl -w net.ipv6.conf.default.disable_ipv6=1
    sysctl -w net.ipv6.conf.all.disable_ipv6=1
    

    Disable iptables for IPv6

    chkconfig ip6tables off
    
  2. Restart something!

    You will have to restart the ssh daemon or the OS for the changes to take effect.

    So restart sshd

    service sshd restart
    

    Or restart the OS itself

    init 6
    

Don't forget you may not have a route to the host and may think about using bridged mode so your DHCP server can hand out a correct address.

You may also want to read the CentOS Wiki for more info about disabling IPv6

share|improve this answer
    
I tried your commands, but they don't appear to have disabled ipv6. I'm still receiving the binding error in the /var/log/secure, and lsof -i :22 is still reporting a type of ipv6 –  Ken Feb 6 at 18:15
    
got sshd to report IPv4, but it didn't fix the problem. :\ –  Ken Feb 6 at 18:46
    
well, reading your post it seems there was two problems, IPv4 routing and ethernet adapter configuration. I am glad you found the problem. –  son_of_fire Feb 7 at 11:33
up vote 2 down vote accepted

Ok, here's how it finally came together:

One of my coworkers recalled that the disk image "might not have a second interface enabled." Since the VBox is set up with NAT as adapter one and Host-only as adapter two, you need to have eth0 and eth1 set up on the disk image. We did not.

To do this:

  • verify that ifconfig |less does not have both eth0 and eth1 listed.
  • cd /etc/sysconfig/network-scripts/
  • cp ifcfg-eth0 ifcfg-eth1
  • cp ifcfg-eth0.bak ifcfg-eth1.bak
  • edit the files and remove anything with HWaddr and change eth0 to eth1 ifcfg-eth1
  • ifup eth1
  • then run ifconfig and take the inet addr of eth1, which was a different IP for me. I'm now working with 192.168.56.101.
  • do init 6 to restart and make sure that eth1 starts automatically now.
  • log in from host: ssh root@192.168.56.101

None of the edits in the question above were actually my problem, but it's all good debug info!!

Cheers,
Ken

share|improve this answer

Your connection is refused because you're trying to ssh as a root user? (I could be wrong).

try:

ssh <host_username>@<ipaddress> 

Also are you using a mac? If so, try turning on remote login from System Preferences->Sharing check Remote Login.

share|improve this answer
    
I have PermitRootLogin yes and I can login as another username that I created. –  Ken Feb 6 at 15:32
    
turn on remote login? but i'm not trying to login to the mac, which is the host machine. I'm trying to login to the VM, which is configured as a CentOS 5.4 box. –  Ken Feb 6 at 15:40
    
Ohh! I'm sorry, I misread your question. My bad! –  Timothy Onggowasito Feb 6 at 15:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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