How to SSH into Red Hat Linux (virtual box guest) from Windows 7 (host)?

13

5

I have Red Hat Enterprise Linux (RHEL) running through Virtual Box, my native OS is Windows 7. From a purely educational standpoint, I want to be able to access RHEL from Win 7 over SSH. I downloaded putty on Windows 7, but don't know how to make it do what I want. Ideally, I would prefer to use the Linux GUI, but am willing to use CLI through Command Prompt if that is all that is available. How do I use SSH to access my RHEL VM? I am trying to expand my knowledge of Linux.

Gary Hunter

Posted 2010-11-11T05:45:41.390

Reputation: 131

Answers

6

The way that I do this is to attach the guest's network adapter to the bridged adapter. What this means is that the guest will obtain an IP address from the same DHCP server that the host obtained its IP address from.

First follow these instructions to attach the guest network adapter to the bridged adapter. You can even do this while the VM is running:

  1. Right click on the network icon in the status bar of the VM window: Screenshot of a VirtualBox VM window after the network icon was right-clicked
  2. Select "Network Adapters..."
  3. In the dialog, select "Bridged Adapter" from the "Attached to:" combo box: Screenshot of the VirtualBox network settings dialog
  4. Click "OK".

You will then need to have RHEL renew its IP address loan. In a terminal, type:

sudo dhclient -r
sudo dhclient

The guest's new IP address is viewable in the output of ifconfig eth0:

Screenshot of the output of ifconfig eth0

In my case, it's 192.168.1.100. I can now ssh into that IP with Putty.

Daniel Trebbien

Posted 2010-11-11T05:45:41.390

Reputation: 393

Thanks for your time to take screenshots. After following your instructions, ifconfig eth0 does not print an inet addr just HWaddr and then the next line is inet6 addr. – SSH This – 2013-09-10T20:32:52.213

1I figured what I was doing wrong, hopefully it will help someone. The "Name" drop down (underneath "Attached to") was a wireless connection. When I switched this to a Gigabit wired connection, your instructions worked perfectly. – SSH This – 2013-09-10T20:52:52.733

THANK YOU @SSHThis - you have helped me infinitely. I feel so stupid. Oh, me. – jdero – 2013-12-14T04:14:42.600

4

Gary,

I'm not sure you got your answer yet...so here goes :-)

You're running Windows 7 as HOST and RHEL as the GUEST operating system. I'm going to assume that your VirtualBox network configuration for RHEL is NAT'd (instead of bridged). This means that you're going to need to use the following command to do port-forward (port 22) from the HOST to the GUEST. From your windows command prompt enter the following command:

VBoxManage modifyvm "vopa" --natpf1 "guestssh,tcp,,22,,22"

Port 22 is the default port used by ssh or putty. Since Windows 7 doesn't use this port the command will forward all network traffic over this port from the HOST to the GUEST. Now from a command prompt on your windows system you can use the following putty command to logon to your RHEL (GUEST) system from your windows system (HOST).

putty userid@localhost

Where 'userid' is the linux user account on your RHEL system. For example if your userid was the root account you would type the following:

putty root@localhost

You will be prompted for the password. Hope that helps :-) --Slick

Slick

Posted 2010-11-11T05:45:41.390

Reputation: 41

BTW, make certain your RHEL system has the Firewall disabled and SELinux disabled. You won't need to install an X-Server (like xming) but if you do have cygwin installed you can use the ssh command instead of putty. – Slick – 2010-12-29T21:58:23.803

Instead of "vopa" specify the name of your RHEL virtual machine. The name that appears in the VirtualBox list when you start the RHEL system. – Slick – 2010-12-29T22:02:07.247

VirtualBox comes with an RDP server though, you could just RemoteDesktop into your RHEL, no need for an X11 server (but if you want one, Xming works great) – nos – 2011-03-04T00:33:10.717

2

This post I found shows how to configure ssh between a guest and host. Although it deals with a Linux host, the main steps deal with configuring the Linux guest.

invert

Posted 2010-11-11T05:45:41.390

Reputation: 4 918

1

If your purpose is to mainly move files around, I would suggest using something like WinSCP or FileZilla.

WinSCP:

WinSCP is an open source free SFTP client, SCP client, FTPS client and FTP client for Windows. Its main function is file transfer between a local and a remote computer. Beyond this, WinSCP offers scripting and basic file manager functionality.

FileZilla:

FileZilla Client is a fast and reliable cross-platform FTP, FTPS and SFTP client with lots of useful features and an intuitive graphical user interface.

It Grunt

Posted 2010-11-11T05:45:41.390

Reputation: 151

0

You'll need cygwin on Windows if you want to forward X11 from your RH VM to Windows.

Alternatively just run '$ startx' and you'll get to the GUI part of the linux install.

RomanT

Posted 2010-11-11T05:45:41.390

Reputation: 149

Thanks. I prefer to go without cygwin though. – Gary Hunter – 2010-11-11T06:01:04.060

Gary, understood. Preference is your choice. Cygwin is the 'natural'/most-popular, albeit you can also go with Xming – RomanT – 2010-11-12T11:25:06.737

0

For the GUI bit you could try the Xming server.

There is a similar question for a FC guest here,
SSH from host machine Win7 to guest Fedora Machine in VirtualBox

nik

Posted 2010-11-11T05:45:41.390

Reputation: 50 788

0

You might be able to use OpenSSH though Cygwin for this. I haven't got the necessary things to try it out with your use-case, but I think it should be doable.

Leif

Posted 2010-11-11T05:45:41.390

Reputation: 400

Oh! I didn't notice that @RomanT had already posted this answer. – Leif – 2010-11-11T17:09:58.537

0

I set up the bridged connection for the guest RHEL6 guest OS (on my OpenSuse Host), using a procedure like that demonstrated by @Daniel Trebbien.

Then I had to run the network configuration commands in RHEL (in particular configuring my eth0 using system-config-network-tui as given in the nice RHEL network configuration tutorial here). This last step is necessary because even if you bridge your adapter, if the guest's network configuration isn't complete, then you can't still access internet or ssh into the guest easily.

nemesisfixx

Posted 2010-11-11T05:45:41.390

Reputation: 2 811

0

Here is how I did the connection/setup on RedHat Linux 6.

  1. In Virtual Box create Adapter 2 "Host Only Adapter".

  2. Start your Linux System.

  3. activate the Adapter 2

    ifconfig eth1 up

assign an ip (choose which you want)

ifconfig eth1 192.168.56.101

You can check the setting by typing ifconfig.

4.Connect to 192.168.56.101 Port 22 with SSH.

To set up setting automaticly at start: add in /etc/sysconfig/network-scripts/ifcfg-eth1

# Virtual Box - My VM HostOnlyAdapter
DEVICE=eth1
BOOTPROTO=static
DHCPCLASS=
HWADDR=08:00:27:04:CD:15
IPADDR=192.168.56.101
NETMASK=255.255.255.0
ONBOOT=yes

Please compare you HWADDR (MAC-adress) in your VM Settings. It should be the same.

Andreas L.

Posted 2010-11-11T05:45:41.390

Reputation: 101