GETTING TO THE CLI - Learning Ubuntu: A Beginners Guide to Using Linux (2016)

Learning Ubuntu: A Beginners Guide to Using Linux (2016)

CHAPTER 3

GETTING TO THE CLI

CLI stands for command line interface, where you can interact with the system by entering lines of text. This is how we interact with our server.

If you decided not to use the recommended method of setting up a VPS on DigitalOcean or another provider, then you can see the CLI on your computers display. When you boot your computer, it will bring you to the CLI, where you can then login.

If you are using a VPS, then you will need a way to connect and view the CLI. We can connect to the VPS by using a protocol called SSH. SSH stands for Secure Shell, which is an encrypted way that we can remote login to our server.

When we signed up for DigitalOcean, they sent us an email with our IP address, username, and password. If you used a similar service, it would also provide you with this information or allow you to set it manually. While you are likely familiar with user names and passwords, you may not be familiar with IP addresses. An IP Address, is a string of numbers that identifies a computer on a network. For our VPS, our IP Address is a public one, which can be accessed from anywhere with an internet connection.

The program I recommend to SSH into your server is called PuTTY. PuTTY is a free SSH client that is open source and supported on Windows. You can download it from the following link:

http://putty.org

The file you download is an executable (.exe) that does not require an install. Once you download it, you can drag it onto your desktop for quick access.

Connecting to your VPS with this tool is very easy. Under Host Name or IP address, put the IP address that was provided. Select SSH as the connection type and then click open. See figure 1 as an example of what it should look like.

Note: Your IP Address will be different than the one in the figure.

Figure 1: Putty Configuration

When you hit connect, you may get a message like the one in Figure 2. Click Yes.

Figure 2: PuTTY Security Alert

LOGGING IN FOR THE FIRST TIME

Now you will be prompted in for the first time. Enter the username root, then the password that was provided.

If you used DigitalOcean, their system requires a password reset the first time you log in. You will need to reenter the provided password and then the new one you wish to set twice. Make sure you follow secure password guidelines and set a secure password for the root user.

Note: Throughout this book, I use tables to explain the different commands that we are going to learn. The first row is the task that we want to do, the second is the command we need to use, and the third is an example of what your CLI will look like. I think this is the best way to depict and explain the commands we are going to learn.

If you were not prompted to change your password, but want to, you can enter the command, passwd. See the table on the next page for more details.

Change My Password

Command

passwd

Result

System will prompt for new password

CLI Display

root@ubuntu:~# passwd

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

NAVIGATION

Do not be intimidated by the white text and black background on the CLI. I know that there is no mouse or graphics, but after a short while, you will be comfortable navigating through the directories on your server. Directory is like a folder that you may have used on a Windows or Mac device. As a person who has used this for a long time, I actually prefer this to having a graphical user interface. Before we do anything else, let’s learn to explore the server. By using the pwd command, we can see the location of the directory that we are currently viewing.

Find Your Current Directory Location

Command

pwd

Result

System will output the directory that you are in.

CLI Display

root@ubuntu:~# pwd

/root

Right now we are in a directory named root, which is essentially the home directory of the user root. There is big difference between this root home directory and the actual root of the system.

The path / is the root of the system, but right now we are in a subdirectory that is named root (/root).

The root of the server is the top directory. Everything is a subdirectory inside of it. From our current location, there are two ways we can go there. Let’s start with the easiest command that will always get us to root.

Go To The Root Directory (/)

Command

cd /

Result

We change to the main root directory

CLI Display

root@ubuntu:~# cd /

root@ubuntu:/#

Now let’s use, pwd again to see where we are at.

Find Your Current Directory Location

Command

pwd

Result

System will output the directory that you are in.

CLI Display

root@ubuntu:~# pwd

/

If you want to see what is in the folder, we can use the ls command.

List Files

Command

ls

Result

Lists the files in the current directory

CLI Display

root@ubuntu:/# ls

bin home lib64 opt sbin usr

boot initrd.img lost+found proc srv var

dev media root sys vmlinuz

etc lib mnt run tmp

We can also go into more detail by adding a flag after ls.

A flag is typed at the prompt as part of our command and adds additional parameters to tell the system what we want.

Try running this command: ls –la

In that example, –la is the flag. The l tells the system that we want to see more details and a lists all the files in the directory, even the hidden ones.

Now, let’s change to the directory named home.

Change Directory

Command

cd home

Result

System moves us to child folder home

CLI Display

root@ubuntu:/# cd home

root@ubuntu:/home#

Note: It is important to understand the difference between parent and child directories. If we have a directory called documents and another inside of it called pictures. Pictures would be a child directory of documents. In this instance we were in the parent directory / and changed it to the child directory /home. If you were not in the parent folder, you could still navigate to home, but after cd, you would have to list the full path (example: cd /home) instead. If you get an error such as, “No such file or directory”, you may need to enter the full path, since you may not be in the right parent directory.

If we want to go back to the root directory we can use another change directory command, which makes going up a directory very easy.

Move Up A Directory Level

Command

cd ..

Result

System moves us to the parent folder

CLI Display

root@ubuntu:/home# cd ..

root@ubuntu:/#

Using cd along with the directory names and .. can allow us to quickly move throughout our server.

QUICK RECAP

1) CLI stands for command line interface, where you can interact with the system by entering lines of text.

2) SSH stands for Secure Shell, which is an encrypted way that we can remote login to our server.

3) An IP Address, is a string of numbers that identifies a computer on a network.

4) PuTTY is a free SSH client that is open source and supported on Windows.

5) The passwd command, allows us to change the current users password.

6) Entering pwd, will provide us with our current location in the server’s directories.

7) Using ls, will list the files and directories in our current directory.

8) Adding a flag, such as –la, after ls, provides us with more details and shows hidden files.

9) We can use cd, to change directories quickly

1. We can move up a folder with cd ..

2. Putting a child directory after cd, will put us in the directory.

1. Example: cd home

3. We can always find root by using cd /

10) The path / is the root of the system, but /root is a child or sub directory named root.