Cannot ssh to Ubuntu server guest on a Mac OSX host

Discussions related to using VirtualBox on Mac OS X hosts.
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by Sasquatch »

jbrose wrote:I can ssh from the Ubuntu VM in Virtualbox to the OSX host, on port 22.
That is not what was asked. The question was: can you SSH to localhost in the VM? I.e. you start the VM, you open a terminal and enter this:

Code: Select all

ssh localhost
If that fails, then you can forward ports all you want, but there is no SSH server daemon listening. You have to install openssh-server before you can use SSH to remote into the machine. After that, you use this command:

Code: Select all

ssh -p 2222 user@127.0.0.1
On the Mac. You can also use localhost, but that might resolve to the link-local IPv6 address and NAT doesn't work with that. Though, I have ssh'ed to localhost from my Linux machines into a VM without any problem.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
jbrose
Posts: 21
Joined: 7. Sep 2011, 17:46
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by jbrose »

I am getting this ...

ssh HostUID@HostNumericIPaddress:2222
ssh: Could not resolve hostname HostNumericIPaddress:2222nodename nor servname provided, or not known

ssh HostUID@HostNumericIPaddress -p 2222
Operation time out


Here are the steps I followed to set it up ...

20) In "Oracle VM VirtualBox Manager" click on "Settings"

21) In "General" window click on "Network" then click on "Port Forwarding"

22) Click on Add port icon "+"
Fill in the fields with
Name Protocol Host IP Host Port Guest IP Guest Port
Rules 1 TCP host static ip 2222 10.?.?.? 22


23) Install SSH server on your VM
sudo apt-get install openssh-server

24) On OS X or whatever host
Go to "System Preferences"

25) Under "Internet & Wireless" click on "Sharing" icon

26) Check "Remote Login" option

27) The "Sharing" window shows you the username and address to SSH to. As in "ssh userid@somecomputer.ws.utk.edu"

28) a) Turn off the guest VM
b) cd /Applications/VirtualBox
c) type VBoxManage modifyvm "Guest VM name" --natpf1 "guestssh,tcp,,2222,,22"
d) Start the guest VM
jbrose
Posts: 21
Joined: 7. Sep 2011, 17:46
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by jbrose »

In a terminal window on my VM ...

1) I did this ...

ssh localhost

and it worked


2) I then di this ...

ssh -p 2222 user@127.0.0.1

and got ....

ssh: connect top host 127.0.0.1 port 2222: Connection refused
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by Sasquatch »

Doing both the command line and the GUI is not a good idea, they do the same. Remove all the rules, then put the VM in Host-Only network, instead of NAT. Then use SSH from the Host to the IP of the Guest, it will probably be 192.168.56.100. That will tell you if things work properly towards the Guest.

After you got that working, change the VM network to NAT (you can do it while it's running) and add the rule for SSH. Then use 'ssh -p <port you used> localhost'. That should get it going, else you got a firewall that's blocking things.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
jbrose
Posts: 21
Joined: 7. Sep 2011, 17:46
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by jbrose »

Ok I have done this ...

1) Shut down the VM and in command line on the host system typed:

VBoxManage modifyvm "My VM name" --natpf1 delete "guestssh"

2) Started the VM and in the Settings->Network window of VirtualBox Manager disabled Port Forwarding

3) Then I tried to select "Host-only Adapter" instead of "NAT" but I am getting an "Invalid Settings Detected" message at bottom of the window and next to it a red hexagon with an exclamation point in it.

with the "OK" button greyed out
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by Sasquatch »

Then it would seem you don't have a Host-Only adapter. Create it from the main GUI preferences. Then try again.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
jbrose
Posts: 21
Joined: 7. Sep 2011, 17:46
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by jbrose »

1) I set up and used a Host-Only network

2) I successfully did SSH from the host to the VM guest

3) I changed the VM network back to NAT and enabled port forwarding with the same earlier settings for ports, etc.

4) I tried these ...

On the VM this worked successfully
ssh -p 22 localhost


On the host machine I tried
ssh -p 2222 localhost
and got ...
ssh: connect to host localhost port 2222: Connection refused
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by Sasquatch »

And if you nmap the Host from the Guest. Or check the firewall? Do you see anything when you check netstat for listening ports (netstat -tln or similar command)?
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
jbrose
Posts: 21
Joined: 7. Sep 2011, 17:46
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by jbrose »

1) I am unfamiliar with nmap. I installed it on the guest VM and ran it from the guest VM using

nmap -v hostipaddress

It said ...
Note: Host seems down. If it is up, but blocking out ping probes try: -PN

2) So I ran it again using

nmap -PN hostipaddress

and got

22/tcp open ssh
and another port

But no reference to port 2222

3) I tried netstat -tln but I am not sure for what I am looking

4) No firewall at the moment
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by Sasquatch »

If nmap doesn't show any results and you must use -PN, then there is a firewall active. For netstat, you'll be looking for something like this:

Code: Select all

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:222            0.0.0.0:*               LISTEN
The first entry is cups, your printing system. The second should be your VM, if it's running, when NAT is enabled with port forwarding. Now, the output may be different, because I don't have a Mac as Host, but Linux.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
jbrose
Posts: 21
Joined: 7. Sep 2011, 17:46
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by jbrose »

1) Used "ufw" on guest VM to open port 22

2) Ran "nmap -v 127.0.0.1" on the guest VM and got ....

PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
631/tcp open ipp

3) Tried "ssh -p 2222 hostipaddress" and got ...

ssh: connect to host hostipaddress port 2222: Operation timed out


Is there something I am supposed to do on host side regarding port 2222? I have just entered it in the GUI port forwarding mechanism in Settings->Network in the Oracle VM VirtualBox Manager

4) For netstat -tln on the VM I get ...

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:6600 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 LISTEN


tcp 0 0 0.0.0.0:222 0.0.0.0:* LISTEN
vbox4me2
Volunteer
Posts: 5218
Joined: 21. Nov 2008, 20:27
Location: Rotterdam
Contact:

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by vbox4me2 »

Did you make a mistake in port forwarding like type 222 instead of 2222 ?
jbrose
Posts: 21
Joined: 7. Sep 2011, 17:46
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by jbrose »

Looking at Settings->Network->Port forwarding in "Oracle VM VirtualBox Manager"

Under the column headings
Host Port is 2222
Guest IP is 127.0.0.1
Guest port is 22

Although when I do an ifconfig in my VM terminal window I get the inetaddr of 10.0.2.15
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by Sasquatch »

Only use Host port and Guest port, leave the addresses empty.

Now, again, are you 100% sure that there is no firewall active on your Host? Did you double check it in System Preferences > Security?
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
jbrose
Posts: 21
Joined: 7. Sep 2011, 17:46
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: Cannot ssh to Ubuntu server guest on a Mac OSX host

Post by jbrose »

1) When I set Port Forwarding leaving the "Host IP" and "Guest IP" blank and putting "2222" in "Host Port" and "22" in "Guest Port" and I click "OK" I get a warning pop-up window that says "The current port forwarding rules are not valid. None of the host or guest port values may be set to zero" Even though they have the 2222 and 22 values in them. It has 2 buttons, "Copy" and "OK," I chose "OK" then clicked "OK" in Port Forwarding window and then "OK" again.

2) "Firewall: Off" and "This computer's firewall is currently turned off"


Tried to SSH to the box and got connection timeout.
Post Reply