Finding Your Way On Ubuntu Server
A quick guide to maintaining your very own Ubuntu Server.
Setting up your server to do what you want is only half of the challenge, the other half is maintaining it.
It’s Not Too Hard
Even if you’ve never used the command line before, it’s not too hard once you get used to it. In fact, you may even prefer it after you learn how much faster and more efficient it is to issue one command instead of navigating a bunch of settings menus to get the job done.
Accessing Your Server
Before you can continue with this guide, you’ll need to access your server’s command line. While there are quite a few ways to do this, I prefer using SSH. SSH, or Secure Shell, is a way to securely access the command line on your server. It’s super easy to set up, and makes sure that no one on your network except for you can see what you’re doing. Connecting via SSH can be done from just about nearly OS, but the process is likely a bit different. To get this set up, I recommend this tutorial by DigitalOcean.
Alternatively, you can always just use the web console that many VPS providers have nowadays. However, I find that many of these don’t give you access to all the features you’d get with SSH, especially copying and pasting. While it may be a bit easier, I still suggest taking a few minutes to learn how to connect with SSH.
Creating An Account
When you first set up a server, you often connect to the root account directly. This means you can do virtually anything you want, which can include installing viruses and breaking critical files. As unlikely as it is for you to break Ubuntu Server by accident, it is still a threat. Creating a normal user account decreases the chances of you bricking the entire system, unless you intentionally do so with the
sudo command (more on that in a bit). The worst a normal user can do is break their own account, or crash the system by using up too many resources, although even that can be prevented by modifying a single configuration file.
Creating The Account
Creating an account in Ubuntu Server is much faster and simpler than creating an account in Windows. Simply run:
[username] with your preferred username. You’ll then be prompted to set a password. Simply type your password and press enter, then type out your password again to verify. Note that you won’t see anything as you type out your password. This is done for security purposes and is completely normal. After you’ve done that, there’s a bunch of other optional information you can fill out (just leave it empty and press enter to continue). The process should look something like this:
Adding user `bob' ... Adding new group `bob' (1001) ... Adding new user `bob' (1001) with group `bob' ... Creating home directory `/home/bob' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for bob Enter the new value, or press ENTER for the default Full Name : Room Number : Work Phone : Home Phone : Other : Is the information correct? [Y/n]
You can now log in to your newly created account, but don’t do that just yet!
Normal accounts on Linux intentionally have limited privileges. However, for maintaining a server, you’ll often need root privileges. The solution to this is the
sudo command, which lets you run a single command as root (or any other user you’d like), without needing to actually log in to the root account. This means that even if you accidentally run a dangerous command, as long as you didn’t prefix it with
sudo, the worst that can happen is you losing the files stored in your home directory. Accounts don’t have access to
sudo by default, so to grant your account access to this, simply run the following command:
sudo adduser [username] sudo
Now, when you log into your account, try running the following:
You’ll be prompted for a password, and the result should be:
sudo should give you your username.
Believe it or not, package management in Ubuntu is much simpler than on Windows, and even Mac OS. While on those operating systems you need to hunt down installers on the internet yourself, Ubuntu gives you a tool in the command line that does all the work of installing and setting up packages for you. It will also take care of installing all pre-requisites for whatever piece of software you install. Not only that, but you can update your system, along with all of your applications with one command. The package manager Ubuntu opts to use is
apt, which is fairly simple to learn and use.
One of the most important things to do on any internet connected device is to ensure it’s up to date. The case is no different on servers. Luckily, the commands to do this are fairly simple and are easy to remember.
First, you’ll need to run the update command, which ensures you’ll get the latest available versions of packages:
sudo apt update
followed by the command to actually upgrade everything:
sudo apt upgrade
Should any prompts pop up, the default option is usually the safest one.
Searching For Software
Searching for software can also be accomplished with
apt. The syntax is
apt search [package name]
This will search for all packages which contain the string of text in them. So,
apt search java will return a list of all available packages which have “java” in the name.
After you’ve found the package you’d like to install, simply run
sudo apt install [package name]
apt will take care of everything for you. You may need to accept the changes (by typing
y and enter), and some packages have additional configuration settings during install. Dependencies are automatically installed with the package, which means you’ll very rarely have to deal with broken packages again!
In the event you ever need to go through the setup process for a package again, you can do so with:
sudo dpkg-reconfigure [package name]
We all make mistakes, and download software we don’t really need. Or, we needed it at some point but not anymore. Either way,
apt also makes this process very simple:
sudo apt remove [package name]
This will remove the package itself, although it often leaves behind configuration files. In the event you later download the package again, your configuration files will remain intact. If you’re sure you don’t need the configuration files, then you can use
sudo apt purge [package name]
After using Ubuntu for a while, and installing/uninstalling packages, you’ll realize that some dependencies are never removed. While this isn’t too big of a problem, if you ever need to free up some space, you can tell
apt to remove dependencies that are no longer required. Simply run the following command:
sudo apt autoremove
Whenever you install applications,
apt will download some files which are needed for the installation (e.g.
.deb files). Although no longer needed after the install is complete, these files will stick around for a bit. In order to remove them, you can run the
sudo apt clean
Linux is way ahead of Windows, especially when it comes to reboots. You’ll very rarely need to reboot Ubuntu, as many updates can be applied by simply restarting or reloading the services that are updated. Every now and then, a kernel update will be released which requires a reboot, unless you have live kernel patching set up. You’ll know when it’s time to reboot because you’ll see a message telling you a reboot is necessary upon logging in. When you see that message, reboot the server by running:
sudo apt update sudo apt upgrade
Searching For A Package
apt search [search term]
sudo apt install [package name]
sudo apt remove [package name]
sudo apt autoremove sudo apt clean