Virtual Box and SSH

2

I have a production server off site and a development server as a virtualbox on my laptop.

My question is how do I setup virtualbox's network before booting the image so that I can SSH between the two?

(Google has a lot on this subject but it is usually people asking how they can ssh between the host and the client)

Sevenearths

Posted 2011-01-11T15:24:23.703

Reputation: 123

Answers

1

You set the networking adapter into bridged mode (virtual box settings). That's all.

If you want to be able to access your development server from the production server, you need to port-forward port 22 to your development computer/virtal box IP.

To access the file system on the production server, you can use scp to copy files back and forth. I wouldn't recommend it however, it's a pain in the ass.

I would recommend you sshfs.

The way sshfs works is, it mounts the remote file system in your local filesystem. Then you just open, edit, save, copy/paste files there, and sshfs does the scp data-transmitting stuff in the background.

Command:

sshfs theUserYouWantToLoginAs@ip.of.target.computer:/ /path/to/folder/where/you/want/to/mount/the/remote/filesystem

example:

sshfs root@74.125.77.99:/ /mnt/sshfs

PS: I would use ssh keys, not a password. Passwords are too weak.

To generate a key:

ssh-keygen -t rsa -b 4096

This generates id_rsa and id_rsa.pub
id_rsa.pub you echo into the authorized_keys file in the .ssh folder in the home directory of the ssh user on the target machine
example:

copy id_rsa.pub file to the target computer
cat ./id_rsa.pub >> /root/.ssh/authorized_keys

Quandary

Posted 2011-01-11T15:24:23.703

Reputation: 1 433

what happens if I need to pull files from the production server onto the development (VB) server? – None – 2011-01-11T15:42:35.443

I would mount the production server's file system as ssh file system. – Quandary – 2011-01-11T21:27:20.040

Note that you can omit user@ from user@ip if the user on the target machine corresponds to the user you're currently logged in with on the development machine. – Quandary – 2011-01-11T21:37:43.170

Maybe I should explain a bit more. – None – 2011-01-11T23:38:38.690

I tried the bridge route but I just got ssh: connection to host xxx.xxx.xxx.xxx port 22: Network unreachable. My setup is: router: 192.168.1.1 - host: 192.168.1.4 - guest: 192.168.1.5 (vb/dev) and I let through 22 for 192.168.1.5 on my router. What I find weird about all of this is I can still ssh from the host machine (192.168.1.4) to the production server – None – 2011-01-11T23:44:05.760

thanks for the sshfs and keys info. But for now I would just be happy to get ssh working – None – 2011-01-11T23:48:47.837

Another thing to note is that I could do this all fine at work with a nat connection. So I think it's router related – None – 2011-01-11T23:56:00.867

Did you switch off all firewalls ? (Windows firewall + iptables) – Quandary – 2011-01-13T08:19:10.410

0

I found a way to ssh into the development server, but it wasn't with the command line so I don't know if this counts as an answer!

In my development (guest) OS, Cent OS, I can connect to my production server in the big wide world by going to:

Places > Connect to Server

and filling out the details as you would normally. (strangely when you select ssh it still asks you for the port you would like to use!?!)

Also. I don't know if this makes a difference but I entered the following into the host before booting the Cent OS image:

VBoxManage modifyvm "Cent OS 5.5" --natpf1 "guestssh,tcp,,22,,22"

recomended from here

Sevenearths

Posted 2011-01-11T15:24:23.703

Reputation: 123