1 00:00:00,000 --> 00:00:02,699 Hello, in this lesson we are going to 2 00:00:02,699 --> 00:00:05,909 cover SCP, which is Secure Copy 3 00:00:05,909 --> 00:00:09,449 Protocol. The Secure Copy Protocol or 4 00:00:09,449 --> 00:00:12,299 SCP helps to transfer computer files 5 00:00:12,299 --> 00:00:16,079 securely from a local host to a remote 6 00:00:16,079 --> 00:00:20,129 host. It is somewhat similar to FTP, but 7 00:00:20,129 --> 00:00:23,549 it adds security and authentication. So 8 00:00:23,549 --> 00:00:25,859 if you are transferring a file again, 9 00:00:26,219 --> 00:00:29,639 from server a to server b, you could use 10 00:00:29,999 --> 00:00:33,689 SCP as the protocol or the command 11 00:00:34,079 --> 00:00:37,169 rather than FTP. And the reason it is 12 00:00:37,169 --> 00:00:41,009 preferred is because it is secure, it 13 00:00:41,009 --> 00:00:43,589 adds more security and authentication. 14 00:00:44,549 --> 00:00:47,189 Now the protocol as I said before, the 15 00:00:47,189 --> 00:00:49,829 protocol is a set of rules used by 16 00:00:49,829 --> 00:00:53,399 computers to communicate. So when SCP 17 00:00:53,399 --> 00:00:55,499 was built, they decided okay, this is 18 00:00:55,499 --> 00:00:58,349 the protocol that SCP should use. And 19 00:00:58,349 --> 00:01:01,139 this is the port that should be used to 20 00:01:01,139 --> 00:01:03,119 transfer a file from one server to 21 00:01:03,119 --> 00:01:08,369 another. The default SCP port is SSH, or 22 00:01:08,369 --> 00:01:12,449 port 22. So there is no different 23 00:01:12,659 --> 00:01:15,299 protocol that was established or setup 24 00:01:15,329 --> 00:01:18,569 for SCP. So it actually leverages on to 25 00:01:18,569 --> 00:01:21,749 the same SSH protocol that we use to 26 00:01:21,749 --> 00:01:25,289 connect from one server to another over 27 00:01:25,289 --> 00:01:29,339 SSH. Now, for this lecture, again, we 28 00:01:29,339 --> 00:01:32,009 needed two Linux machines. One is for 29 00:01:32,009 --> 00:01:34,049 the client, and one is for the server. 30 00:01:34,529 --> 00:01:38,219 The client is where we have the file, 31 00:01:38,399 --> 00:01:40,559 and the server is where we want to 32 00:01:40,559 --> 00:01:44,219 transfer that file to. For the client, I 33 00:01:44,219 --> 00:01:47,219 have my Linux machine and it is called 34 00:01:47,219 --> 00:01:50,189 MyFirstLinuxVM. For the server, I 35 00:01:50,189 --> 00:01:52,859 have a server which is exactly the same 36 00:01:52,859 --> 00:01:55,079 as client as well, but I had named it 37 00:01:55,079 --> 00:01:59,159 LinuxCentOS7. So the process is 38 00:01:59,219 --> 00:02:03,209 SCP, the process in the graphical 39 00:02:03,209 --> 00:02:06,509 way is you have a client A and client B 40 00:02:06,509 --> 00:02:10,199 server. Now client A wants to copy a file 41 00:02:10,199 --> 00:02:13,469 over to server B. Now it will use the 42 00:02:13,469 --> 00:02:17,699 protocol SCP or the command SCP, but it 43 00:02:17,789 --> 00:02:23,189 actually transferred that over through 44 00:02:23,639 --> 00:02:25,679 the protocol we already have in place, 45 00:02:25,679 --> 00:02:28,649 and that is SSH. So there is no new 46 00:02:28,649 --> 00:02:31,439 protocol for that, it actually piggybacks 47 00:02:31,619 --> 00:02:36,209 on SSH. And of course, the SSH port is 48 00:02:36,209 --> 00:02:39,899 22. And the service where SSH daemon 49 00:02:40,169 --> 00:02:42,449 should be running on the recipient or 50 00:02:42,449 --> 00:02:49,199 the remote server in order to accept incoming traffic. 51 00:02:50,129 --> 00:02:52,949 Okay, what's the process? The SCP command 52 00:02:52,949 --> 00:02:55,019 to transfer files to the remote server, 53 00:02:55,019 --> 00:02:56,639 first of all, you have to log in 54 00:02:56,639 --> 00:02:59,999 yourself. Then create a file any file, 55 00:03:00,029 --> 00:03:03,509 let's say we in this lesson, or 56 00:03:03,509 --> 00:03:05,489 in this lab, we'll create a file called 57 00:03:05,489 --> 00:03:08,789 jack. Once the jack file is created, 58 00:03:08,819 --> 00:03:12,659 then we will simply run the command scp, 59 00:03:13,379 --> 00:03:16,889 the file named jack, iafzal is the 60 00:03:16,889 --> 00:03:20,549 user name that actually exists on the 61 00:03:20,549 --> 00:03:25,304 remote server, @, 192.168.1.x 62 00:03:25,304 --> 00:03:28,379 is the actual IP of 63 00:03:28,379 --> 00:03:30,179 the remote server. Of course, we 64 00:03:30,179 --> 00:03:34,139 replace that x with the digit that is 65 00:03:34,139 --> 00:03:36,569 the digit of your remote server, and the 66 00:03:36,569 --> 00:03:39,805 last part is colon slash home slash iafzal, 67 00:03:39,805 --> 00:03:41,909 this is where you want the file to go 68 00:03:41,969 --> 00:03:44,849 to, in this directory, on the remote 69 00:03:44,849 --> 00:03:47,249 server. Once it's connected, then it's 70 00:03:47,249 --> 00:03:50,039 going to ask you to enter username and 71 00:03:50,039 --> 00:03:52,829 password, and it will transfer the file 72 00:03:53,039 --> 00:03:55,919 successfully. Now, enough is enough. 73 00:03:56,069 --> 00:03:59,159 Let's actually start our Linux machine 74 00:04:00,179 --> 00:04:02,189 which I have already started, and I have 75 00:04:02,189 --> 00:04:04,859 already logged into my PuTTY. This is my 76 00:04:04,859 --> 00:04:07,409 Linux machine and I refer to as my 77 00:04:07,409 --> 00:04:09,569 client machine because this is the one 78 00:04:09,569 --> 00:04:11,639 that connects to the server. And this 79 00:04:11,639 --> 00:04:14,549 machine hostname is MyFirstLinuxVM. 80 00:04:15,659 --> 00:04:18,959 Who is logged in? whoami, I'm logged in 81 00:04:18,988 --> 00:04:22,469 as myself. Alright follow the directions 82 00:04:22,469 --> 00:04:25,019 here. I'm going to create a file called 83 00:04:25,019 --> 00:04:27,449 jack in my home directory, in my home 84 00:04:27,449 --> 00:04:29,489 directory slash home slash iafzal. 85 00:04:30,029 --> 00:04:34,229 I'll go ahead and do touch jack. When I do 86 00:04:34,229 --> 00:04:37,229 ls -ltr, you will see I have a 87 00:04:37,229 --> 00:04:40,559 file called jack, it has zero bytes. Now 88 00:04:40,979 --> 00:04:43,319 I want to transfer that but before I 89 00:04:43,319 --> 00:04:44,939 transfer it, let's put something in there 90 00:04:44,939 --> 00:04:47,609 just to make sure it is transferred with 91 00:04:47,609 --> 00:04:50,159 the right content. So let's do vi on 92 00:04:50,159 --> 00:04:52,889 jack and just put 93 00:04:53,970 --> 00:05:03,747 Jack is Jerry's Uncle. That's it. 94 00:05:04,620 --> 00:05:09,180 Let's do ls -ltr. Now you see, it 95 00:05:09,180 --> 00:05:12,840 has total bytes 22. Perfect. Now we need to 96 00:05:12,840 --> 00:05:15,810 transfer this file to our remote server. 97 00:05:16,080 --> 00:05:18,210 But before we transfer that file to the 98 00:05:18,210 --> 00:05:20,400 remote server, we wanted to know what is 99 00:05:20,400 --> 00:05:23,040 the IP address of their remote server. 100 00:05:23,310 --> 00:05:24,810 So I'm going to go into my remote 101 00:05:24,810 --> 00:05:28,920 server, which I also have opened. And 102 00:05:28,920 --> 00:05:33,253 I'm going to do ifconfig enp0s3 103 00:05:33,253 --> 00:05:35,220 because that's the interface 104 00:05:35,250 --> 00:05:38,400 where the IP is assigned, and the IP is 105 00:05:38,400 --> 00:05:43,230 192.1681.58. Beautiful. Let's go 106 00:05:43,230 --> 00:05:45,570 back to my client. And now this time, 107 00:05:45,600 --> 00:05:48,180 I'm going to run the command. Let's 108 00:05:48,180 --> 00:05:51,000 clear the screen so you could see it 109 00:05:51,000 --> 00:05:54,300 better. Now run the command scp, the 110 00:05:54,300 --> 00:05:57,420 name of the file, which is jack, the 111 00:05:57,420 --> 00:05:59,820 name of the user who is going to log in 112 00:06:00,090 --> 00:06:01,950 to the remote server, what is the remote 113 00:06:01,950 --> 00:06:09,390 server 192.168.1.56, yes, and 114 00:06:09,390 --> 00:06:13,290 then colon slash, where is it going to 115 00:06:13,290 --> 00:06:17,361 or which directory, it is going to /home/iafzal. 116 00:06:17,361 --> 00:06:19,770 hit enter, and it's going to ask you 117 00:06:19,770 --> 00:06:22,770 for the password. If you are doing SCP 118 00:06:22,770 --> 00:06:24,360 for the first time, then it's going to 119 00:06:24,360 --> 00:06:26,280 ask you for the fingerprints where you 120 00:06:26,280 --> 00:06:29,310 have to type in yes, and then enter the 121 00:06:29,310 --> 00:06:34,440 password. So go ahead and password. And 122 00:06:34,440 --> 00:06:37,260 it says a jack, which is a file name 123 00:06:37,290 --> 00:06:40,620 100% transferred and the size was 22. 124 00:06:40,620 --> 00:06:42,270 And this is the time it took to 125 00:06:42,270 --> 00:06:45,210 transfer. Okay, I got this message on 126 00:06:45,210 --> 00:06:46,890 the client but let's confirm on the 127 00:06:46,890 --> 00:06:48,600 server whether it was transferred or 128 00:06:48,600 --> 00:06:50,790 not. So, first of all, it was 129 00:06:50,790 --> 00:06:53,010 transferred as iafzal. So I have to 130 00:06:53,010 --> 00:06:57,300 log in as iafzal, so whoami, I am 131 00:06:57,300 --> 00:07:00,060 iafzal, beautiful. Now which 132 00:07:00,060 --> 00:07:03,600 directory am I logged into? I am in my 133 00:07:03,600 --> 00:07:05,310 home directory because that's where I 134 00:07:05,310 --> 00:07:07,680 transferred the file right. Now I will 135 00:07:07,680 --> 00:07:10,440 do ls -ltr to check if that jack 136 00:07:10,440 --> 00:07:15,420 file came in. It did, perfect. Now is 137 00:07:15,420 --> 00:07:17,250 this the right file that came in? Let's 138 00:07:17,250 --> 00:07:21,840 cat it. We did the cat, Jack is Jerry's 139 00:07:21,840 --> 00:07:25,560 uncle, perfect. This is how the SCP 140 00:07:25,560 --> 00:07:28,500 works. And you could also do the same 141 00:07:28,500 --> 00:07:32,700 thing by the way, SCP to go into this 142 00:07:32,700 --> 00:07:34,920 remote server if you want to pull 143 00:07:35,100 --> 00:07:37,860 something out of that server from server 144 00:07:37,860 --> 00:07:40,200 to the client and you have just have to 145 00:07:40,200 --> 00:07:43,980 reverse the command. Anyway, try it out. 146 00:07:44,250 --> 00:07:46,740 And these are the couple of commands a 147 00:07:46,740 --> 00:07:48,540 few commands that I wanted to cover and 148 00:07:48,540 --> 00:07:50,760 very important commands when you are 149 00:07:50,760 --> 00:07:52,680 dealing with transferring files from one 150 00:07:52,680 --> 00:07:54,508 server to another. 151 00:07:54,508 --> 00:07:56,842 [No audio]