1 00:00:06,840 --> 00:00:09,516 - All right, our next topic is about SSH. 2 00:00:09,516 --> 00:00:11,370 SSH is secure shell. 3 00:00:11,370 --> 00:00:13,680 Why would you want to use secure shell? 4 00:00:13,680 --> 00:00:15,900 Well, for the simple reason 5 00:00:15,900 --> 00:00:19,143 that it provides a remote shell access. 6 00:00:20,040 --> 00:00:22,320 The thing is that many people are working with Linux 7 00:00:22,320 --> 00:00:24,180 but they are working with Linux in cloud 8 00:00:24,180 --> 00:00:25,920 or as a virtual machine. 9 00:00:25,920 --> 00:00:26,850 And if that's the case 10 00:00:26,850 --> 00:00:29,880 you have no direct access to your Linux machine. 11 00:00:29,880 --> 00:00:32,340 That is why you need secure shell. 12 00:00:32,340 --> 00:00:33,900 In order to use secure shell 13 00:00:33,900 --> 00:00:37,020 you need to install it and you need to enable it. 14 00:00:37,020 --> 00:00:38,250 If you're on Ubuntu, 15 00:00:38,250 --> 00:00:41,550 sudo apt install openssh-server. 16 00:00:41,550 --> 00:00:43,020 And if you're on Red Hat, 17 00:00:43,020 --> 00:00:44,430 well by default on Red Hat, 18 00:00:44,430 --> 00:00:48,750 you will find that ssh is normally already installed. 19 00:00:48,750 --> 00:00:50,100 If that is not the case, 20 00:00:50,100 --> 00:00:52,680 sudo dnf install openssh-server 21 00:00:52,680 --> 00:00:55,764 followed by sudo systemctl enable. 22 00:00:55,764 --> 00:00:58,143 The (indistinct) is now sshd. 23 00:00:59,550 --> 00:01:00,450 Next, 24 00:01:00,450 --> 00:01:04,710 you need an SSH client to access the SSH server. 25 00:01:04,710 --> 00:01:06,570 If you're on Linux and MacOS, 26 00:01:06,570 --> 00:01:10,290 a native command line SSH client is available. 27 00:01:10,290 --> 00:01:13,500 If you're on Windows you can use MobaXterm. 28 00:01:13,500 --> 00:01:16,740 MobaXterm is an easy to use Windows utility 29 00:01:16,740 --> 00:01:19,470 in which you enter the IP address of your target machine 30 00:01:19,470 --> 00:01:23,463 and you can easily connect to your target machine using SSH. 31 00:01:24,420 --> 00:01:27,900 Now, SCP is a convenient tool that allows you to copy files 32 00:01:27,900 --> 00:01:31,320 from the local computer to the remote computer. 33 00:01:31,320 --> 00:01:33,000 And why am I mentioning it here? 34 00:01:33,000 --> 00:01:37,830 For the simple reason that SCP is a part of the SSH package. 35 00:01:37,830 --> 00:01:39,480 So you install SSH, 36 00:01:39,480 --> 00:01:41,700 you get SCP for free. 37 00:01:41,700 --> 00:01:46,336 So the command looks like scp/etc/hosts 38 00:01:46,336 --> 00:01:51,237 to 192.168.29.111:/tmp/. 39 00:01:51,237 --> 00:01:56,190 And you can see that the 192.168.29.111, 40 00:01:56,190 --> 00:01:58,140 that's the name of the server. 41 00:01:58,140 --> 00:02:01,140 And the name of the server has a colon behind it 42 00:02:01,140 --> 00:02:03,840 and after that, there's the path. 43 00:02:03,840 --> 00:02:08,840 Now let me demonstrate how we can get started with SSH. 44 00:02:10,950 --> 00:02:13,473 So for this demo I'm starting on Ubuntu, 45 00:02:14,550 --> 00:02:19,550 using sudo apt install openssh-server. 46 00:02:19,920 --> 00:02:24,030 Because on Ubuntu you don't get SSH by default. 47 00:02:24,030 --> 00:02:25,830 Well, depends on Ubuntu server. 48 00:02:25,830 --> 00:02:27,360 There's an option that is asking you, 49 00:02:27,360 --> 00:02:29,970 hey, do you want to install OpenSSH? 50 00:02:29,970 --> 00:02:32,400 And if you answer yes, you get it, 51 00:02:32,400 --> 00:02:34,953 but otherwise you don't. 52 00:02:35,790 --> 00:02:37,800 Now I'm going to use ip a. 53 00:02:37,800 --> 00:02:40,980 Ip a, one of the first commands that we learned about, 54 00:02:40,980 --> 00:02:43,752 is showing me that this Ubuntu machine 55 00:02:43,752 --> 00:02:47,550 is 192.168.29.142. 56 00:02:47,550 --> 00:02:50,130 That's the IP address that I'm going to use. 57 00:02:50,130 --> 00:02:53,190 So let me go to the CentOS machine. 58 00:02:53,190 --> 00:02:54,720 And from the CentOS machine 59 00:02:54,720 --> 00:02:59,063 I'm using ssh student@192.168.29.141. 60 00:03:05,130 --> 00:03:05,970 And there we go. 61 00:03:05,970 --> 00:03:07,560 This is what's happening the first time 62 00:03:07,560 --> 00:03:10,740 that you make connection with the remote SSH server. 63 00:03:10,740 --> 00:03:14,850 It's probably complaining about some key fingerprint. 64 00:03:14,850 --> 00:03:15,690 What is that? 65 00:03:15,690 --> 00:03:16,923 That's the identity. 66 00:03:18,180 --> 00:03:21,870 The SSH client is keeping the identity of the host 67 00:03:21,870 --> 00:03:25,050 that it has connected with in the past. 68 00:03:25,050 --> 00:03:27,060 That's an additional level of security. 69 00:03:27,060 --> 00:03:28,380 So if you answer yes, 70 00:03:28,380 --> 00:03:30,600 you store the identity locally, 71 00:03:30,600 --> 00:03:35,370 and the next time that you log in to this remote server 72 00:03:35,370 --> 00:03:37,950 you will not be prompted anymore. 73 00:03:37,950 --> 00:03:41,460 Your local client knows that you are on the right server. 74 00:03:41,460 --> 00:03:42,720 And oops, do you see that? 75 00:03:42,720 --> 00:03:45,930 I opened an SSH session to myself. 76 00:03:45,930 --> 00:03:47,280 That's not what I wanted. 77 00:03:47,280 --> 00:03:50,460 I wanted to go to Ubuntu, 142. 78 00:03:50,460 --> 00:03:53,490 Aha, let's try it again, 142. 79 00:03:53,490 --> 00:03:55,680 Again, the prompt for the identity, 80 00:03:55,680 --> 00:03:57,810 I'm entering my student password, 81 00:03:57,810 --> 00:04:00,210 and look at that, welcome to Ubuntu. 82 00:04:00,210 --> 00:04:03,183 I'm on Ubuntu and I can do whatever I want. 83 00:04:04,020 --> 00:04:05,820 Well, you know what I want? 84 00:04:05,820 --> 00:04:07,650 I want to create a file, 85 00:04:07,650 --> 00:04:12,090 echo greetings from ubuntu 86 00:04:12,090 --> 00:04:13,610 to ubunut.txt. 87 00:04:17,730 --> 00:04:19,590 What is ubunut? 88 00:04:19,590 --> 00:04:21,210 That's just a file name. 89 00:04:21,210 --> 00:04:25,380 And I'm going to use scp of ubunut.txt 90 00:04:25,380 --> 00:04:30,380 to 192.168.29.141:/tmp/. 91 00:04:33,360 --> 00:04:35,430 That's the SCP command, 92 00:04:35,430 --> 00:04:37,950 and SCP is pretty convenient as well. 93 00:04:37,950 --> 00:04:41,010 So I'm entering yes because I want to copy it over. 94 00:04:41,010 --> 00:04:42,210 And there we go, 95 00:04:42,210 --> 00:04:46,680 I'm copying it over using the student account. 96 00:04:46,680 --> 00:04:51,680 Now you can also copy it over using another user account. 97 00:04:51,960 --> 00:04:55,500 In SSH you can always use username@. 98 00:04:55,500 --> 00:04:59,850 Username@ in front of the name of your server 99 00:04:59,850 --> 00:05:02,580 will connect as that specific user. 100 00:05:02,580 --> 00:05:06,060 Now it happens to be that on CentOS there's the root user. 101 00:05:06,060 --> 00:05:09,810 So I am being prompted for the root user password here, 102 00:05:09,810 --> 00:05:14,810 and that is copying ubunut to the root user home directory. 103 00:05:15,180 --> 00:05:20,180 So if I use sudo cat /root/ubunut.txt, 104 00:05:23,340 --> 00:05:26,190 then you can see greetings from ubuntu. 105 00:05:26,190 --> 00:05:27,390 And hey, did you notice? 106 00:05:27,390 --> 00:05:30,030 I wasn't prompted for any sudo password. 107 00:05:30,030 --> 00:05:35,030 So it seems that my sudo cat is working the way I wanted it. 108 00:05:36,300 --> 00:05:37,443 That's all for now.