1 00:00:00,530 --> 00:00:04,180 So far we've been controlling the server via a virtual monitor provided by 2 00:00:04,180 --> 00:00:05,310 Virtual Box. 3 00:00:05,310 --> 00:00:08,180 Everything we type is going directly to the server. 4 00:00:08,180 --> 00:00:09,950 But to connect servers out on the Internet, 5 00:00:09,950 --> 00:00:13,746 you would use the Secure Shell program, or SSH. 6 00:00:13,746 --> 00:00:18,740 SSH connects you to a terminal on a remote computer, and it encrypts everything you 7 00:00:18,740 --> 00:00:23,250 do so no one can eavesdrop on the passwords and commands you're sending. 8 00:00:23,250 --> 00:00:26,260 From now on we're going to want to connect via SSH. 9 00:00:26,260 --> 00:00:27,280 So let's set that up now. 10 00:00:28,560 --> 00:00:31,430 SSH usually listens for network traffic on port 22, 11 00:00:31,430 --> 00:00:35,410 and the SSH on our Virtual Server will be no different. 12 00:00:35,410 --> 00:00:39,925 We can tell Virtual Box to open a port on our local computer, and send all 13 00:00:39,925 --> 00:00:44,908 network traffic that it receives on that port to a port on your Virtual Server. 14 00:00:44,908 --> 00:00:48,876 So we're going to open port 2222, that's 2,222, 15 00:00:48,876 --> 00:00:53,700 on our computer and forward all traffic to port 22 on our Virtual Server. 16 00:00:54,800 --> 00:00:59,310 When we use the SSH command to connect to port 2222 on our computer, 17 00:00:59,310 --> 00:01:02,680 we'll wind up talking to the SSH service on our Virtual Server. 18 00:01:03,880 --> 00:01:08,416 So here in the main Virtual Box app we're going to select our Guest computer, 19 00:01:11,343 --> 00:01:18,329 And we're gonna choose settings for it, and we're gonna click on the Network tab. 20 00:01:18,329 --> 00:01:22,312 Here for Adapter 1 we're going to expand the Advanced options set and 21 00:01:22,312 --> 00:01:24,670 we're gonna click on Port Forwarding. 22 00:01:24,670 --> 00:01:30,535 This is what we're going to use to forward port 2222 traffic to port 22 on the Guest. 23 00:01:30,535 --> 00:01:35,900 We'll click the plus icon over here to add a new rule, and 24 00:01:35,900 --> 00:01:39,340 we can name it whatever we want but we're going to call it SSH so 25 00:01:39,340 --> 00:01:41,030 that we know what service we're forwarding. 26 00:01:42,250 --> 00:01:43,750 The protocol should be TCP. 27 00:01:43,750 --> 00:01:46,256 We're gonna leave the host IP blank so 28 00:01:46,256 --> 00:01:49,951 that it will forward traffic from any host to any guest. 29 00:01:52,361 --> 00:01:55,553 And we're going to set the host port to 2222 so 30 00:01:55,553 --> 00:02:00,360 that we don't conflict with the existing SSH service on our host. 31 00:02:00,360 --> 00:02:05,469 We'll forward all traffic that we get on port 2222 to port 22 on the Guest, 32 00:02:05,469 --> 00:02:08,870 that'll be the guest SSH service. 33 00:02:09,910 --> 00:02:13,470 Since we're probably going to be running a web server on this virtual server, 34 00:02:13,470 --> 00:02:16,140 we're also going to want to forward port 80. 35 00:02:16,140 --> 00:02:19,380 Again, this might conflict with an existing web server 36 00:02:19,380 --> 00:02:21,260 running on port 80 on our host. 37 00:02:21,260 --> 00:02:26,440 So we're going to forward traffic from port 8080 to port 80 on the Guest. 38 00:02:27,490 --> 00:02:29,860 So let's click the plus sign to add a new rule. 39 00:02:29,860 --> 00:02:36,318 We're going to label this one HTTP, protocol is still TCP. 40 00:02:36,318 --> 00:02:39,633 We'll leave the host IP blank again, and 41 00:02:39,633 --> 00:02:44,188 we'll forward from host port 8080 to guest port 80 42 00:02:46,911 --> 00:02:51,720 Click OK when you're done, and click OK to save the settings changes. 43 00:02:53,090 --> 00:02:56,490 Now SSH isn't actually installed on our guest OS yet. 44 00:02:56,490 --> 00:02:57,980 We're going to need to install that now. 45 00:02:59,680 --> 00:03:02,990 We'll use Ubuntu's Package Manager to automatically download and 46 00:03:02,990 --> 00:03:04,570 install the software for us. 47 00:03:05,700 --> 00:03:10,740 So we're going to start with the commands sudo, that stands for super user do. 48 00:03:10,740 --> 00:03:14,500 Basically sudo is going to give administrative access on this computer, 49 00:03:14,500 --> 00:03:17,190 since we need it in order to install new software. 50 00:03:18,310 --> 00:03:24,096 Then we'll run the command for the Package Manager, that's apt-get, space. 51 00:03:24,096 --> 00:03:30,440 We'll run the install sub command to apt-get, and then 52 00:03:30,440 --> 00:03:34,488 we need to provide the name of the actual software package we want to install. 53 00:03:34,488 --> 00:03:38,420 That's called openssh, all one word, 54 00:03:38,420 --> 00:03:43,380 followed by -server, since this is going to be an SSH server not a client. 55 00:03:44,680 --> 00:03:49,380 Once all that's entered press Enter to run the command, and it'll ask for 56 00:03:49,380 --> 00:03:50,120 your password. 57 00:03:51,160 --> 00:03:53,943 So enter the password that you set up when installing Ubuntu. 58 00:03:56,952 --> 00:03:59,977 It'll ask if you wanna continue, and the default will be Yes, so 59 00:03:59,977 --> 00:04:05,711 just hit Enter And 60 00:04:05,711 --> 00:04:08,666 then it will download and install the software automatically and 61 00:04:08,666 --> 00:04:10,930 put you back to the system prompt when it's done. 62 00:04:12,618 --> 00:04:17,220 Now we're ready to switch back to a terminal on our host computer, and 63 00:04:17,220 --> 00:04:19,600 try connecting to our guest computer via SSH. 64 00:04:21,370 --> 00:04:27,226 Now we would have to type some complicated command like SSH, our user name, 65 00:04:27,226 --> 00:04:32,820 127.0.0.1 to specify that we wanna connect to our local host. 66 00:04:32,820 --> 00:04:40,100 And then we'd have to specify the port number with a flag-p, port 2222. 67 00:04:40,100 --> 00:04:43,840 That's what we would have to type the way things are set up now. 68 00:04:43,840 --> 00:04:46,070 But that's a complicated command to have to remember. 69 00:04:47,160 --> 00:04:51,520 So, instead, what we're going to do is edit our SSH configuration 70 00:04:51,520 --> 00:04:52,660 to make it easier to connect. 71 00:04:54,010 --> 00:04:59,190 We're going to accomplish this by editing the SSH configuration on our host. 72 00:04:59,190 --> 00:05:03,920 SSH configuration is stored within a directory in your user's home folder 73 00:05:03,920 --> 00:05:04,710 named SSH. 74 00:05:04,710 --> 00:05:08,380 So let's create that directory right now in case it doesn't exist. 75 00:05:08,380 --> 00:05:13,460 So mkdir ~/.ssh. 76 00:05:13,460 --> 00:05:17,097 And now we're going to open the SSH folder within our favorite editor. 77 00:05:17,097 --> 00:05:21,560 And we'll create a new file within it named config. 78 00:05:23,100 --> 00:05:25,810 There should be no extension on the config file name. 79 00:05:27,330 --> 00:05:30,770 Within that config file, we're going to create an entry for a new host. 80 00:05:30,770 --> 00:05:34,020 Note that this doesn't mean the host to our virtual machine. 81 00:05:34,020 --> 00:05:38,060 This means host as in a host computer out there somewhere on the Internet. 82 00:05:39,360 --> 00:05:43,420 We're going to call this Host hostcom, same name as our guest machine. 83 00:05:43,420 --> 00:05:47,270 The host name can be anything we want, but it's better to have it match the name of 84 00:05:47,270 --> 00:05:49,430 the virtual machine just to avoid confusion. 85 00:05:51,040 --> 00:05:52,950 Then in the line immediately under that, 86 00:05:52,950 --> 00:05:55,780 we're going to add a HostName configuration value. 87 00:05:57,470 --> 00:06:00,950 And this is going to be the actual address that we attempt to connect to 88 00:06:00,950 --> 00:06:02,080 to talk to this host. 89 00:06:03,890 --> 00:06:07,720 Now since this is a virtual machine running on our local computer, 90 00:06:07,720 --> 00:06:10,910 we're going to connect to local host. 91 00:06:10,910 --> 00:06:16,839 That's at the IP address 127.0.0.1, that's the standard IP address for local host. 92 00:06:18,380 --> 00:06:20,785 We're also going to add a port entry, and 93 00:06:20,785 --> 00:06:23,345 specify the port that it should connect to. 94 00:06:26,407 --> 00:06:29,220 Let's save this and then we can quit out of our editor. 95 00:06:30,370 --> 00:06:33,775 Now that our SSH configuration is complete, we can go back into 96 00:06:33,775 --> 00:06:37,318 our terminal on our host computer and type the command SSH again. 97 00:06:37,318 --> 00:06:41,318 But this time all we have to type is our user name and 98 00:06:41,318 --> 00:06:47,148 the name of the host entry that we set up in our configuration, hostcom. 99 00:06:47,148 --> 00:06:51,242 It'll look that entry up in the configuration and 100 00:06:51,242 --> 00:06:57,199 realize that it wants to connect to 127.0.0.1 port 2222. 101 00:06:57,199 --> 00:07:00,483 Since this is the first time connecting to our guest computer via SSH, 102 00:07:00,483 --> 00:07:03,640 it's going to ask if we're sure we want to continue connecting. 103 00:07:03,640 --> 00:07:04,760 We'll go ahead and type yes. 104 00:07:05,800 --> 00:07:09,079 Now I'll be asked to enter the password that we set up while configuring Ubuntu. 105 00:07:12,423 --> 00:07:15,454 And that's it, we're now connected to a shell on our guest 106 00:07:15,454 --> 00:07:17,710 Linux computer from a terminal on our host.