LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 10-21-2009, 04:17 PM   #1
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Trying to ssh into VM from host


Hello, all. I have a Slackware virtual machine set up in VirtualBox with "NAT" networking, and I'm trying to set it up so that I can ssh into it from the host. I'm doing this because I want to learn more about ssh and networking in general, but there aren't any other machines in the house that run a *nix/BSD, so I have to use a VM.

I've tried following the guide in the VirtualBox user manual about port forwarding:

Quote:
p, li { white-space: pre-wrap; } You can set up a guest service which you wish to proxy using the command line tool VBoxManage. You will need to know which ports on the guest the service uses and to decide which ports to use on the host (often but not always you will want to use the same ports on the guest and on the host). You can use any ports on the host which are not already in use by a service. An example of how to set up incoming NAT connections to an ssh server on the guest requires the following three commands:
VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22 VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222
Here are the commands I put in to apply to my VM:

Code:
mrcode@linuxbox:~$ VBoxManage setextradata "SlackVM" "VBoxInterlan/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP
VirtualBox Command Line Management Interface Version 3.0.8
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

mrcode@linuxbox:~$ VBoxManage setextradata "SlackVM" "VBoxInterlan/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22
VirtualBox Command Line Management Interface Version 3.0.8
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

mrcode@linuxbox:~$ VBoxManage setextradata "SlackVM" "VBoxInterlan/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222
VirtualBox Command Line Management Interface Version 3.0.8
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

mrcode@linuxbox:~$
I'm guessing the lack of error messages means that it all worked. However, when I try the following:

Code:
ssh -p 2222 slackvm
it just gives me:
Code:
ssh: Could not resolve hostname slackvm: Name or service not known
I'm a real newb to this, so if there's something I'm doing very wrong (or not doing at all), please let me know. I got that the -p option is for port selection from the man page...is that right?

I've also tried ssh'ing to it by it's IP (10.0.2.15), but then it just sits there for a little bit (a couple minutes at least) and then tells me the connection timed out. Is there something I need to do in the VM in that time that it's just sitting there?

I've searched on Google about this issue, but none of the other forum threads and/or guides really apply to what I want to do...at least not exactly. I've searched LQ, too, but I can't find another thread that deals specifically with this issue.

I hope this thread is in the right place, but if it fits better in LInux - Networking, then please move it there.

Last edited by MrCode; 10-21-2009 at 04:18 PM.
 
Old 10-21-2009, 06:21 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Forgive me if this is obvious, but does your slackware install have an ssh server running ('ps -A' should show a line for the sshd daemon)?

Are you able to ping the machine? This will show you if your network is behaving the way you expect it to. Because it is on a private network, you will only be able to access it from the host.

You could try getting it going without port forwarding first, ie, just using the default ssh port (this will make it a lot simpler).

Last edited by neonsignal; 10-21-2009 at 06:22 PM.
 
Old 10-21-2009, 11:54 PM   #3
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864

Original Poster
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Quote:
Forgive me if this is obvious, but does your slackware install have an ssh server running ('ps -A' should show a line for the sshd daemon)?
According to both the boot-text startup parade and "ps -A", sshd is running. And trust me, when it comes to this kind of thing, nothing's obvious . I've never tried this before.

Quote:
Are you able to ping the machine? This will show you if your network is behaving the way you expect it to. Because it is on a private network, you will only be able to access it from the host.
I can't seem to get through to it at all. I did a "ping 10.0.2.15" but just sits there, not even giving any error messages. I'm pretty sure that's what the IP of the VM is, because doing an ifconfig in the VM gives that as the "inet addr" field.

Quote:
You could try getting it going without port forwarding first, ie, just using the default ssh port (this will make it a lot simpler).
I don't know how to set the port settings back to default...unless you just mean to exclude the -p option when I try to get in again, in which case it doesn't seem to be working.
 
Old 10-22-2009, 01:38 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
I did a "ping 10.0.2.15" but just sits there, not even giving any error messages.
Which just means you are getting no response.

I wouldn't have thought you would need to set up the port forwarding, since you are not going to access the guest virtual machine from anywhere except the host (and the host is on the local NAT). It should be sufficient to just do the following in the host:

Code:
ssh 10.0.2.15
You will use IP addresses rather than hostnames (since you probably don't have any name resolution in place).

A few more questions:

1. Is the guest able to access other machines (eg, from the guest, can you ping 10.0.2.1, or any IP addresses on the real network)? (if not, then for some reason the virtual box network adapter is not working)

2. Are you using the same username on both the host machine and the guest virtual machine? (if not, you can do something like ssh user@10.0.2.15).

3. What version of VirtualBox are you using?

You could also try using host networking instead of NAT in the virtual box configuration of the guest (effectively this places the guest onto the real network, which can simplify things).

My understanding is that your setup is as follows: you have a host machine called 'linuxbox', a guest machine connected using a (virtual) NAT called 'slackvm' running sshd, and you are attempting to ssh from the host machine into the guest.
 
Old 10-22-2009, 02:29 AM   #5
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864

Original Poster
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Quote:
You could also try using host networking instead of NAT in the virtual box configuration of the guest (effectively this places the guest onto the real network, which can simplify things).
Thanks for the tip! I switched the networking to "Host-only Adapter" and it appears I can access the VM via ssh now. I can't access the Internet through the VM anymore, though (this is probably because it's no longer using the wlan0 interface of the host like it was when I was using NAT).

Also, I got this message when I did a "ssh 192.168.56.101" (the IP assigned to the VM after switching):

Code:
The authenticity of host '192.168.56.101 (192.168.56.101)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)?
Is this anything to be worried about? (I've censored the RSA key).

One last thing: while the VM was still on NAT, I could only ping outside websites and the host. I tried ssh'ing into the host, but it just gave me a "Connection refused" message. I'm guessing this just means that I could, in theory, go the other way around using NAT? I'm guessing all I'd need to do is do some configuring on the host to allow the VM to connect.
 
Old 10-22-2009, 03:36 AM   #6
j1alu
Member
 
Registered: Apr 2009
Distribution: debian gnu/linux
Posts: 798

Rep: Reputation: Disabled
Quote:
Thanks for the tip! I switched the networking to "Host-only Adapter" and it appears I can access the VM via ssh now. I can't access the Internet through the VM anymore, though (this is probably because it's no longer using the wlan0 interface of the host like it was when I was using NAT).
i just did exactly the same, thats why i know:
you need to add a second network adapter in the network-settings (one NAT for networking and another host-only for ssh-connection).
i hope this is correct for you too and it will work.

from guest to host it should be :
ssh 192.168.56.1
and from host to guest it should be:
ssh 192.168.56.101
per default, but you may check with ifconfig. ssh 10.0.2.15 doesnt work over here, i cant tell you why (or what 10.02.15 is good for)

about the RSA-keyring you dont need to be worried. Its the usual procedure the first time the connection is made. as far i understand :-) .

Last edited by j1alu; 10-22-2009 at 03:44 AM.
 
Old 10-22-2009, 05:32 AM   #7
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Are you sure you want to continue connecting (yes/no)?
Is this anything to be worried about? (I've censored the RSA key).
As j1alu says, it is quite normal. The security problem is that if someone was intercepting the communications, then ssh could be connecting to another machine (masquerading as the real one). So the warning (if you were being pedantic about security) is so that you can check for a key match.

Quote:
I can't access the Internet through the VM anymore, though (this is probably because it's no longer using the wlan0 interface of the host
I can't test this out here (I don't have a wireless interface), but the network settings on VirtualBox may allow you to select which host interface you wish to use.

Quote:
while the VM was still on NAT, I could only ping outside websites and the host. I tried ssh'ing into the host, but it just gave me a "Connection refused" message.
Connection refused could mean that sshd is not running, or that it has been secured to only respond to certain addresses. Changing to a NATed network won't change this.

When the guest was on the NAT, there are two ways for it to connect to the host, because the host has two IP addresses, one facing out to the home network (192.168.56.X), one facing in to the virtual NAT (might be 10.0.2.2).

I had another look at the NAT interface on VirtualBox, and it seems that you have to do port forwarding in order to communicate to the guest (even from the host). Part of the problem is that VirtualBox is not necessarily running as root, so it can't just automatically route the standard port addresses. I'm not sure why your VBoxManage forwarding didn't work (though I did notice that you had VBoxInterlan instead of VBoxInternal, perhaps a typo).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora 10/unable to ssh out from box to remote host (SSH within LAN ok) huskeypm Linux - Networking 3 04-14-2009 07:37 PM
x host with ssh rsca0070 Linux - Networking 1 09-08-2006 02:50 PM
SSH Host Error carlosinfl Linux - Networking 6 07-30-2006 10:03 AM
ssh + pop3 with kmail: Could not connect to host localhost, but ok without ssh Emmanuel_uk Linux - Networking 0 07-20-2006 04:56 PM
How to setup a host.deny and host.allow for SSH? explorer1979 Linux - Security 2 01-31-2005 05:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration