Linux Basics Homework

hoomanpb
Project1-LinuxBasics.docx

Project 1

Create a Word (or equivalent) file that documents your completion of this project with the question and your answer. Where you see red text, make sure you take a screenshot of your progress. Feel free to add text or comments to your submission if you feel it needs clarity. Make sure the document is professional, clear, and self-explanatory. You can use the built-in screenshot tool within OSX/Windows or add software that gives you the ability to use arrows, boxes, etc. for more clarity. If I cannot read your answers due to size, quality, pixilation, or lack of explanation of what I’m looking at, I’ll assume it’s wrong.

Commands are illustrated with a $ symbol indicating that they are run as a non-privileged user.

If you get stuck and need help, try using the man command to pull up the manual for a tool in question (E.g. $ man cat ). If you’re still stuck, use Google.

Note, the tasks towards the end are weighted heavier than the tasks in the beginning of the project. E.g. missing the last answer will bring your score down MORE than 7.14%.

Instructions:

Log into your AWS account.

Click on Services > Lightsail

Create an instance

Create a Linux, OS Only Ubuntu instance

1. Name your instance CSUN-[your-first-name] and take a screenshot to add to your documentation.

You may have to wait up to 60 seconds for the instance to be provisioned.

Click the console icon on your newly created instance to launch a browser console.

You’ll notice your username is ubuntu and your hostname is ip-[private-ip-given-by-aws].

Change your hostname to csun-[your-first-name]

$ sudo hostname csun-[your-first-name]

Close the browser console window and re-open it to see the changes made.

2. Take a screenshot showing the new hostname.

Update the repository by issuing:

$ sudo apt-get update -y

Update the packages by typing:

$ sudo apt-get upgrade

If you get a prompt like this, select: keep the local version…

Note your instance’s private IP address by typing:

$ ifconfig

3. Highlight the private IP address and take a screenshot.

Determine what directory you are currently in by typing:

$ pwd

4. Take a screenshot of the directory you’re in.

Create blank file using the touch command with the name of csun-[your-first-name1]:

$ touch csun-[your-first-name1]

Make sure the file was created by issuing:

$ ls

5. Take a screenshot of the file permissions of the newly created file.

$ ls -l

Create a new file called csun-[your-first-name2] with the phrase “Hello Class” in it.

$ echo Hello Class > csun-[your-first-name2]

6. Verify the file was created, note the file size of 12 bytes and that the permissions are the same. Take a screenshot of the file, byte size, and permissions of the file:

$ ls -l

Create a third file called csun-[your-first-name3] with the first line being “Line 1” and the second line being “Line 2”. See what happens when you try using the same method as above to add a second line to the text file:

$ echo Line 1 > csun-[your-first-name3]

$ echo Line 2 > csun-[your-first-name3]

$ cat csun-[your-first-name3]

Only the second line appears in the file. This is because the single “>” will push the contents proceeding “echo” into the file and it overwrites “Line 1”.

Delete csun-[your-first-name3] by typing:

$ rm csun-[your-first-name3]

This time create a file called csun-[your-first-name4] with the first line being “Line 1” the second line being “Line 2” and the third line being “Line 3”:

$ echo Line 1 > csun-[your-first-name4]

$ echo Line 2 >> csun-[your-first-name4]

$ echo Line 3 >> csun-[your-first-name4]

$ cat csun-[your-first-name4]

Copy csun-[your-first-name4] to a file called csun-[your-first-name5]

$ cp csun-[your-first-name4] csun-[your-first-name5]

7. Display the files, their size, and permission. Take a screenshot.

Modify csun-[your-first-name5] using the text editor NANO

$ sudo nano csun-[your-first-name5]

Add lines to the file so your text file has Line 1 to Line 15

8. Take a screenshot of the text file being edited in NANO with all 15 lines.

When done, press CTRL + X > y > ENTER to exit and save the document.

Cat the text file to make sure all 15 lines are there.

$ cat csun-[your-first-name5]

Use the head and tail tool to show the top 10 lines and bottom 10 lines of the text file respectively.

$ head csun-[your-first-name5]

$ tail csun-[your-first-name5]

9. Take a screenshot of the output for both head and tail.

Modify the file permissions of csun-[your-first-name5] so that only the owner has read/write permissions (the exact command is intentionally omitted).

10. Take a screenshot proving only the csun-[your-first-name5] text file was changed to -rw-------

After using the cat command to display the contents of the text file, use the grep command to search for “Line 11” in the text file:

$ cat csun-[your-first-name5] | grep “Line 11”

Use the “.” (period symbol) as a wildcard to get Line 10, Line 11, Line 12, Line 13, Line 14, and Line 15 in the results:

$ cat csun-[your-first-name5] | grep “Line 1.”

Take the output of the last command and use the cut tool to display only the numbers of each line. Looking at the manual for the cut tool ($ man cut), we can see option -d will set the delineator (how to break up the columns) and option -f will set the field (which field we want to see). Imagine converting the text file to an Excel file. You need decide and tell the system which part of the text goes into Column A and which goes into Column B and so on. In this example, its simple since each line has two parts: Line and a number separated (delineator) by a SPACE. We’d want to specify column 1 for the Line field or column 2 for the number of each line.

Pipe the output of the prior cat and grep commands into the following cut command:

$ … | cut -d “ “ -f 2

Let’s pipe the results into one more command sort to get the results in descending order instead of ascending order. Looking at the manual for the sort command ($ man sort), the -r option reverses the results since by default the sort command will list the results in ascending order (which it’s already in).

$ … | sort -r

Linux stores users, user IDs, the group users are part of, the shell the user uses to login (if applicable), and user’s home directory in the /etc/passwd file that is readable by any user (globally readable). Passwords used to be obfuscated and stored in this file, but they are now stored in the /etc/shadow file.

Here’s an output of the /etc/passwd file with a red box around the username section of the first user:

11. Use the skills you just learned with cat and cut to display a list of ONLY the usernames. Take a screenshot of your command and the output that looks like the example below (the command has been omitted).

Create a new user [your-first-name] by typing:

$ useradd [your-first-name]

Notice how a standard user doesn’t have permissions to add a new user. You’ll need to insert sudo before the command. You can either re-type the command with sudo in front or use the shortcut sudo !! to run the sudo command along with the last typed command (!!) in the bash history (useradd [your-first-name])

$ sudo !!

Note, it didn’t ask for a password for the new user. Make sure you add a password for the newly created user by typing:

$ passwd [your-first-name]

Again, note how you don’t have permission to do that without running sudo. Try it again after elevating privileges.

View the /etc/passwd file using the less command this time to make sure you can find your newly created user:

$ less /etc/passwd

With the less tool, you can use the arrow keys to scroll up and down. You can also use the forward slash ( / ) to search the file interactively.

Press the “q” key on your keyboard to exit the less tool.

12. Use the skills learned in this project to view the /etc/passwd file, locate just the new user you created in the prior step, dissect the results to show only the USERNAME:HOME DIRECTORY. In my example, the results from a single command would be: mike:/home/mike. Take a screenshot like the one below (the command has been omitted). Make sure your screenshot has the command used and the results.

Redirect the standard output using the > symbol to take the output of your last command and make it the input of a text file called [your-first-name]-project1. Use the cat command to show what’s inside and use the file command on your text file to prove it’s in fact a text file.

13. Take a screenshot of the command used to redirect the output into the input of a text file, the contents of the new text file, and the output of the file command showing it’s a text file.

In the final step, let’s zip the [your-first-name]-project1 file using the zip tool.

$ zip mike-project1

Note, the zip tool is not installed.

Use the package manager apt-get to install the tool.

$ sudo apt-get install zip -y

Using the -y option, we won’t get asked to confirm the disk space to be used for the tool. We’re preemptively saying yes.

Now the zip tool can be used:

$ zip [your-first-name]-project1.zip [your-first-name]-project1

14. Take a screenshot proving that your newly created zip file is an archive file format using a tool demonstrated previously in this project.