Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
Thus far, we've been controlling the virtual Linux server as if we were seated in front of it at its dedicated keyboard. Servers out on the network will expect you to connect via SSH. Let's configure SSH now.
-
0:00
So far we've been controlling the server via a virtual monitor provided by
-
0:04
Virtual Box.
-
0:05
Everything we type is going directly to the server.
-
0:08
But to connect servers out on the Internet,
-
0:09
you would use the Secure Shell program, or SSH.
-
0:13
SSH connects you to a terminal on a remote computer, and it encrypts everything you
-
0:18
do so no one can eavesdrop on the passwords and commands you're sending.
-
0:23
From now on we're going to want to connect via SSH.
-
0:26
So let's set that up now.
-
0:28
SSH usually listens for network traffic on port 22,
-
0:31
and the SSH on our Virtual Server will be no different.
-
0:35
We can tell Virtual Box to open a port on our local computer, and send all
-
0:39
network traffic that it receives on that port to a port on your Virtual Server.
-
0:44
So we're going to open port 2222, that's 2,222,
-
0:48
on our computer and forward all traffic to port 22 on our Virtual Server.
-
0:54
When we use the SSH command to connect to port 2222 on our computer,
-
0:59
we'll wind up talking to the SSH service on our Virtual Server.
-
1:03
So here in the main Virtual Box app we're going to select our Guest computer,
-
1:11
And we're gonna choose settings for it, and we're gonna click on the Network tab.
-
1:18
Here for Adapter 1 we're going to expand the Advanced options set and
-
1:22
we're gonna click on Port Forwarding.
-
1:24
This is what we're going to use to forward port 2222 traffic to port 22 on the Guest.
-
1:30
We'll click the plus icon over here to add a new rule, and
-
1:35
we can name it whatever we want but we're going to call it SSH so
-
1:39
that we know what service we're forwarding.
-
1:42
The protocol should be TCP.
-
1:43
We're gonna leave the host IP blank so
-
1:46
that it will forward traffic from any host to any guest.
-
1:52
And we're going to set the host port to 2222 so
-
1:55
that we don't conflict with the existing SSH service on our host.
-
2:00
We'll forward all traffic that we get on port 2222 to port 22 on the Guest,
-
2:05
that'll be the guest SSH service.
-
2:09
Since we're probably going to be running a web server on this virtual server,
-
2:13
we're also going to want to forward port 80.
-
2:16
Again, this might conflict with an existing web server
-
2:19
running on port 80 on our host.
-
2:21
So we're going to forward traffic from port 8080 to port 80 on the Guest.
-
2:27
So let's click the plus sign to add a new rule.
-
2:29
We're going to label this one HTTP, protocol is still TCP.
-
2:36
We'll leave the host IP blank again, and
-
2:39
we'll forward from host port 8080 to guest port 80
-
2:46
Click OK when you're done, and click OK to save the settings changes.
-
2:53
Now SSH isn't actually installed on our guest OS yet.
-
2:56
We're going to need to install that now.
-
2:59
We'll use Ubuntu's Package Manager to automatically download and
-
3:02
install the software for us.
-
3:05
So we're going to start with the commands sudo, that stands for super user do.
-
3:10
Basically sudo is going to give administrative access on this computer,
-
3:14
since we need it in order to install new software.
-
3:18
Then we'll run the command for the Package Manager, that's apt-get, space.
-
3:24
We'll run the install sub command to apt-get, and then
-
3:30
we need to provide the name of the actual software package we want to install.
-
3:34
That's called openssh, all one word,
-
3:38
followed by -server, since this is going to be an SSH server not a client.
-
3:44
Once all that's entered press Enter to run the command, and it'll ask for
-
3:49
your password.
-
3:51
So enter the password that you set up when installing Ubuntu.
-
3:56
It'll ask if you wanna continue, and the default will be Yes, so
-
3:59
just hit Enter And
-
4:05
then it will download and install the software automatically and
-
4:08
put you back to the system prompt when it's done.
-
4:12
Now we're ready to switch back to a terminal on our host computer, and
-
4:17
try connecting to our guest computer via SSH.
-
4:21
Now we would have to type some complicated command like SSH, our user name,
-
4:27
127.0.0.1 to specify that we wanna connect to our local host.
-
4:32
And then we'd have to specify the port number with a flag-p, port 2222.
-
4:40
That's what we would have to type the way things are set up now.
-
4:43
But that's a complicated command to have to remember.
-
4:47
So, instead, what we're going to do is edit our SSH configuration
-
4:51
to make it easier to connect.
-
4:54
We're going to accomplish this by editing the SSH configuration on our host.
-
4:59
SSH configuration is stored within a directory in your user's home folder
-
5:03
named SSH.
-
5:04
So let's create that directory right now in case it doesn't exist.
-
5:08
So mkdir ~/.ssh.
-
5:13
And now we're going to open the SSH folder within our favorite editor.
-
5:17
And we'll create a new file within it named config.
-
5:23
There should be no extension on the config file name.
-
5:27
Within that config file, we're going to create an entry for a new host.
-
5:30
Note that this doesn't mean the host to our virtual machine.
-
5:34
This means host as in a host computer out there somewhere on the Internet.
-
5:39
We're going to call this Host hostcom, same name as our guest machine.
-
5:43
The host name can be anything we want, but it's better to have it match the name of
-
5:47
the virtual machine just to avoid confusion.
-
5:51
Then in the line immediately under that,
-
5:52
we're going to add a HostName configuration value.
-
5:57
And this is going to be the actual address that we attempt to connect to
-
6:00
to talk to this host.
-
6:03
Now since this is a virtual machine running on our local computer,
-
6:07
we're going to connect to local host.
-
6:10
That's at the IP address 127.0.0.1, that's the standard IP address for local host.
-
6:18
We're also going to add a port entry, and
-
6:20
specify the port that it should connect to.
-
6:26
Let's save this and then we can quit out of our editor.
-
6:30
Now that our SSH configuration is complete, we can go back into
-
6:33
our terminal on our host computer and type the command SSH again.
-
6:37
But this time all we have to type is our user name and
-
6:41
the name of the host entry that we set up in our configuration, hostcom.
-
6:47
It'll look that entry up in the configuration and
-
6:51
realize that it wants to connect to 127.0.0.1 port 2222.
-
6:57
Since this is the first time connecting to our guest computer via SSH,
-
7:00
it's going to ask if we're sure we want to continue connecting.
-
7:03
We'll go ahead and type yes.
-
7:05
Now I'll be asked to enter the password that we set up while configuring Ubuntu.
-
7:12
And that's it, we're now connected to a shell on our guest
-
7:15
Linux computer from a terminal on our host.
You need to sign up for Treehouse in order to download course files.
Sign up