Transcript for:
Remote Server Administration with SSH and FTP

Hello again, as you know I'm Eli the Computer Guy over here for Everyman IT and today's class is SSH and FTP for remote administration. So you know you have this nice little Linux server but you need to put it off in a data center somewhere and you don't want to have to keep running to the data center every time that you want to do something to the server. Well by using SSH and by using FTP you can remotely administer any Linux server. SSH is something called secure shell. So basically what you can do is you can open up the CLI, the command line interface, from anywhere using something called a terminal emulator as long as SSH is installed on your server. We're going to show you how to do that. So you open up the little terminal emulator. and you can run all the commands as if you were sitting right in front of the computer. So whether you want to run top, whether you want to run apt-get, whether you want to change the interfaces file, anything that you can do sitting in front of that computer, you can do using SSH. Now, of course, if you need to get files up to the server, so this is a web server, you need to upload new files for the web part, if you need to upload a program that you're going to be installing, etc. the easiest way to do that is FTP. There are of course, you know being Linux, there's 20 ways to skin a cat, but basically today I will show you how to use FTP because by and large it's the easiest and it's the thing that most people understand the best. So this class is SSH and FTP for remote administration. Give me a second and we'll dive right in. So the first thing we'll talk about is SSH, secure shell. So again, like I say, this is where you use something called a terminal emulator. I use something called Putty to open up a shell environment within the Linux server. So you can do... literally anything that you could do locally. So anything, if you plugged in a keyboard and did that, you can do the same. So my servers that are up on the internet, I can be a thousand miles away and administer them just as well as if I was sitting in front of them. Now the first thing for Secure Shell is you have to install the Secure Shell server. So a lot of people get confused because so many people use Secure Shell and Linux. A lot of newbies don't realize that you actually have to install it. It's not just a component that's there. Remember, for Linux servers, the people that create these distributions figure that you know what you want. So they're not going to install anything that they don't need to install because, again, they don't want to give you too much if you don't want it. In order to install Secure Shell in Ubuntu, it's just very simple. We just use the app.get install command, and it's sudo. sudo apt-get install Can you guess what the command is? Oh yes, it's so complicated. SSH. And that's it. sudo apt-get install ssh and that will download and install the SSH server. Once you do that, it's working. So now, any of your users can use SSH to get into that server. If you do not have a firewall up and running, like literally anybody that has a normal user account account can get in. This doesn't have permissions, you know Linux doesn't have remote access permissions the way Windows does. As soon as you install SSH, any user account is able to use the SSH. Now the big thing with SSH is it is a networking service, so it does use port 22. So if you have UFW installed or if you have firewalls or port forwarding or any of that, basically... You have to make sure that port 22 is open. If port 22 is not open, SSH just isn't going to work. That's how it is. So port 22 has to be open. And then finally, to connect to the server, you need a terminal emulator. So I will show you. We'll go on the computer. You know, I administer from a Windows computer, so I use something called Putty. They have Windows terminal emulators for every type of operating system. My little iPhone. I have a terminal. emulator for the iPhone and the iPhone is actually able to connect to my server up on the internet. So with that information on Secure Shell, let's go over to the computer and show you how this works. Like I say, it's dirt simple but it makes life so much better once you set this up. So here we are, sitting back at the Ubuntu server. Now the first thing that we need to do to be able to use SSH is, of course, install the SSH software. So all we do is we do sudo apt-get install. This is just the normal procedure for installing any type of software out of the software repository. Then space, and all you do is SSH. That's the name of what you're using. Then you hit enter. It'll read the lists, yada yada yada, and now it has installed the SSH software. During this process, you may or may not get a little prompt to do yes or no, and of course you do yes. So now SSH is installed, and it is up and running on this computer. So the first thing that we need to do in order to be able to connect to the server is we need to know the IP address of the server so we know what we're connecting to. So we'll do ifconfig. And now we can look up at eth0. It says inet address, and it's 10.1.10.12. So that is the IP address that we will plug in when we connect into the server. And then the next thing that we need to make sure, since you guys are newbies, is to make sure that the firewall is either down. or that the rules are correct to allow you to connect to the server. So we do sudo ufw status, and this is the command to show you the status of the UFW firewall. If you are using a different type of firewall, of course use whatever command is required to take a look at that firewall. So it says that the status for the UFW firewall is inactive, so we don't have to worry about port 22 being blocked. If UFW was active, you would either have to disable it, or again, you would have to allow port 22 connections. So now that we've made sure that SSH is running and it's all good on this server, we are going to go over to a computer to remotely connect to this server. So through the magic of virtualization, we have now flipped over to my desktop computer. So this is a Windows computer, and I have this program called Putty on it. So Putty is just a free program you can download and order. That's a terminal client, so it allows you to connect to an SSH server. So we just double-click. We get this little box. Here we'll plug in the 10.1.10.12, so this is the IP address of the server. Putty does give you a lot of configuration possibilities. We won't play with that now. And then all you do is you click Open. It may give you a warning message, it may not. This time it didn't give me a warning message. So it just says, do you want to log in? So yes, I'll do Eli. And I'll log in 1, 2, 3, 4, 5, 6. And I am now logged into the server. So you can see Eli at server. So this is that Ubuntu server that we were just on. I am remotely controlling it from another computer. So if I do sudo top. It'll show me the processes that are running on the server. If I do, let's say, lsl, it'll show me the files that are on the server. I can change directory to root. I can make directories. I can remove directories. I can mount drives. Basically, I can do anything using this terminal emulator through SSH that I could if I was sitting in front of the server itself. That's why SSH is just so wonderful and so powerful. So that's all you have to do to use SSH. Basically, you just install the SSH software onto the server. Then all you do is you find out what the IP address of the server is, of course, so you can connect to it, and then make sure that either your firewall is down or the secure way of doing it is make sure your firewall is up, but that you have rules that allow you to access port 22. Remember, if port 22 is blocked, You can't use SSH. Then, once you've done that, you download some type of terminal emulation software. Again, like I say, for Windows, I use PuTTY. For my iPhone, I have a terminal emulator. I bought for $5 for my iPhone. So any type of computer device out there, you can buy a terminal emulator for anywhere from $5 to $10. And then once you do that, you just turn on the terminal emulator software. You plug in the IP address, and you're good to go. That's it. all there is to SSH. So now that I've shown you SSH, let's go back out to the real world and I'll show you FTP. Okay, so now you understand how to install the SSH server software and how to connect to your Linux server using a terminal emulator. Again, like I say, this is great because whether your computer, your server is sitting in the next room or whether it's sitting all the way out in the internet and you're in Ecuador, you can just connect to your server. lickety-split and do whatever maintenance that you need to do. Now the question is, is how do you upload or download files to the server? Now, you know by default you cannot upload or download files to your Linux server. You need to install FTP software to allow this to happen. Now the the FTP software I prefer is something called VS FTPD, so this is very secure file transfer protocol daemon. So in order to install this onto your server, all you have to do is you do sudo apt-get install vs FTPD. This will go out to the repository and it will grab the very secure FTP daemon and basically this is the FTP server software for your server. So once you have this installed you will now be able to upload and download files from your server once you change a couple of configuration settings. Now the configurations for VS FTPD are stored in text files and it's stored in the FTP server. in the etcvsftpd.conf file. So as we talked about in other classes, most configuration files in Linux are stored in basically normal text files. The file that the vsftpd that contains the configuration is the etcvsftpd.conf file. So basically, the configuration file So, when you install VSFTPD, you are going to need to change a couple of the configurations in here to make it work properly. So in order to open this up, in order to edit it, I would suggest you use Vim or whatever text editor you like to use. And so, of course, you do sudo vim forward slash etc forward slash vsftpd.com, and that will open up this text file. Now, inside of this configuration file, this text file, you are going to see a number of settings. Some of these settings have been what is called, they've been commented out. You will see. a pound sign in front of them. In the Linux world, if you put a pound sign in front of a line of code, that tells the server to ignore that line of code. So basically, that line of code does not exist. Well, there are a couple of settings that you have to make sure don't have a pound sign in front of them. You have to make sure that they have not been commented out. Those two settings are local. equals yes. This setting right here says that local user accounts are allowed to use FTP. So if you install the FTP server and then you try to access it using an FTP client and you haven't uncommented this out, you will not be able to connect to the server. So the first thing you have to make sure is that you uncomment this out. So there may be a pound sign in front of this line of code. You want to make sure that you erase that. that pound sign again using Vim as an editor. At this point in time, you should understand how to use Vim. The next thing is to make sure that write underscore enable equals yes is not commented out. What this is, and this is one of the important ones, this says that people can write to the server. So by default, people can download stuff from the server. So when you install VS FTPD, people will be able to just download pictures, they'll be able to download music, videos, etc. They will not, nobody will be able to upload by default. So what you have to do is you have to make sure that this line of code doesn't have a pound sign in front of it. So write underscore enable equals yes, this means that people are actually allowed to write up to the server. If this is commented out, you will not be able to upload anything to the server. Pretty simple. So once you get. get done editing this, you save and quit out of Vim, like you should know how to do right now, and you need to restart this VS FTPD server. to make sure that it pulls up these new configuration files. Because remember, if you change configuration files for a service and you don't restart the service, the service could keep going along using the old configuration files. So with VSFTPD just being it, Linux being Linux, you do have to restart the service in a slightly different way. So the command to restart the VSFTPD service is sudo service vsf. F T P D space restart. That's the command you have to use to restart the VS FTPD service. You could, you know, stop the service so sudo space service space VS FTPD stop. Or you could start it, etc. But this is how you restart the VSFTPD service. You don't do the etc slash initd slash vsftpd space restart. You don't do that. You use this command right here. Once you've restarted the service, then you can use whatever FTP client you want to connect to the server. Now again, remember, make sure if you have a firewall configured for your server, you open up the appropriate ports for FTP. or you just turn off the firewall. The firewall will block, of course, the FTP ports if it's set up. So once you make sure that the firewall is open, then you can use any client that you want to connect to your FTP server to upload and download files. I prefer a piece of software called FileZilla. This is a free FTP client you can download for Windows. I use Windows for my desktop, so I like it. FileZilla. Again, FTP clients are kind of like antivirus software where everybody has their own opinion and everybody thinks everybody else is an idiot if they use anything else. So use whatever you want. There's Qt, FTP, I don't know there's Teapot FTP I think there is. There's a hundred different versions of FTP clients. Basically all you need to know is once you have set up your server you just get whatever FTP client you want to use and use it. Again like I say I like FileZilla. Filezilla, just do a Google search for Filezilla, download it. All you do is whatever FTP client you're using, you plug in the IP address or the domain name for your server, then you tell it the username for the user account and the password for the user account and you're in lickety split. You are now able to upload, download, etc. You may have to play with permissions. We did that users, groups, and permissions class before. You may have to play with some permissions, but otherwise it should be pretty easy. So let's go over to the server. And I'll show you how this all actually works. So here we are again, sitting back at the Ubuntu server screen. So now the first thing, of course, that we have to do is install vsftpd. So the command for that is sudo apt get install vsftpd. install and then vsftpd and then enter. So it's reading the lists and it's installing the server. So vs, very secure, ftpdaemon has now been installed. on the system. Now that the software has been installed on the system, we have to go into the vsftpd.conf file to make sure that it is configured properly so that system users can access the FTP and that they can upload files via FTP. So of course, to edit this.conf file, we do sudo vim vsftpd.conf and hit enter. So we are now in the etc vsftpd.conf file. Now the things that we need to see, now here on this installation we see that they are already correct. Down here where it says local underscore enable equals yes, this is it allows local users to be able to log in to the ftp service. So especially now that we are new. especially now that we're playing around, this is the easiest thing to do. So I can use my Eli account to access the server via FTP. Now the next thing that we need to see, and it is uncommented here, is the write underscore enable equals yes. Now this is big because remember FTP can do two things. It can allow you to download files and it can allow you to upload files. And remember in the Linux world, they will give you the most basic of anything they can ever give you. and then allow you to create the configurations as need be. So if this write underscore enable is commented out, you will not be able to upload files. You will only be able to download files. Now, Since this is uncommented, this will work fine. Again, we opened this with Vim, so if we did need to edit, all we would have to do is press A, and then we can edit as need be. So if I wanted to comment this out, I could do that. If I want to uncomment, then I can backspace. When you're done, hit escape, colon, WQ, and that's it. So now we saved and exited out of that file. So I'll clear the screen again. So now that we've edited the.conf file, of course we need to restart the service. So for VSFTPD, as we talked about, it's a little different for restarting the service. We do sudo service vsftpd restart. And then we hit enter. So now the VSFTPD service has been restarted. it's really that simple. So we've installed VSFTPD, we've edited the.conf file, the configuration file, and we've restarted the service. Now to show you how this works, let's go over to an FTP client to show you how easy it is to connect to the server now. So now I'm going to open up FileZilla, this is the FTP client that I prefer to use, and now I can just log in to the FTP of the server. So it's 10.1.10.12 is the IP address of the server, like we find out for SSH. Then the username is just Eli, and the password is 123456, and then we hit quick connect. Say establish, and look, if you look right here, you will see we are now inside the FTP server. So that file, the server that we built, It will now drop us into the home directory, so home forward slash Eli. If we want to get out to the root or www, we can just click up here on the root. This shows us the other files and folders in the system. And then we can navigate that way. So we can scroll down to the var, www. So if we needed to edit something or delete something in the www folder or upload, et cetera, That's all you would have to do. So literally, once you set up the VS FTPD for the server, you can use any FTP client to access it. Again, like I say, I like using FileZilla. You might use Qt FTP or T-Timer FTP or God knows. There's a million FTPs out there. But once you set up the FTP server on your server, then you can access it using any FTP client. So with that, let's go back out to the real world and have some final thoughts. So those are probably the most important concepts for remote administration that you guys need to understand. Like I say, SSH and FTP. SSH allows you to interact with the server as if you were sitting right in front of it. And then FTP is what allows you to upload or download files to or from the server. Again, all this is pretty simple. SSH, you just have to install the server. So sudo apt-get install ssh. Remember... The port it uses is port 22. So if you have the firewall enabled or if you have other firewalls or port forwarding and any of that stuff, remember port 22 has to get pointed to your server. And then finally, once you've done that, all you need to do is you need to use a terminal input. like I say, I like putty, and use that to open secure shell to the server and then you're administering it. It's really that simple. Again, FTP, it is just about as simple. We use or I like the VS FTP program, very secure FTP. All you do, sudo apt-get install vsftp. Once you do, the main thing with the FTP is you do have to change a couple things in the configuration file. So you go to etcvsftpd.conf, that's the configuration file, open it up, I would suggest Vim, whatever you like to use. Then remember, pound local underscore enable should equal yes, that allows local users to be able to log in, and then pound write underscore enable equals yes. This means you can write. That's all you have to do. Once you've changed at least those configuration files, you have to restart the service. Always remember to restart the service. Again, sudo etc init period d vsftpd for daemon. Start or restart service, that will bring everything online. This will allow you to use any FTP client you like. Like I say, I like FileZilla, it's just simply what I use. Again, like a lot of things, everybody has their own thing that they like. Some people like Qt FTP, etc. Use whatever you like, but the fact is, once you have VS FTP set up, you can use any FTP. client that you choose. And so that's really all there is for remote administration. You know, now that you understand this, you know, at our users class, we talked about being able to change home directories. And in our users class, we said how to add users. So let's say if this is a web server that you want to administer, you want maybe one of your employees to be able to upload data. you can create a user account for them and you can change their home directory to the www directory so basically they can log in and then when they log in they're automatically in the www directory in ftp and they can simply only upload files to there you don't have to worry about them wandering all over your system this is where uh you know security and all these other things that we've talked about you know start to start to come into play again you know with ufw with with network working in the firewall, this is where you can start opening the ports you need to use, port 22, port 80, etc. and close all the other ports that you don't need to use. As with everything, I think this is all pretty simple. Just remember secure shell allows you to administer your server remotely and FTP allows you to upload or download files remotely. If you understand those two things, it's all pretty simple. So as you know, I'm Eli the Computer Guy over here for Everyman IT. This class was SSH and FTP for remote administration, and I look forward to seeing you at the next one.