ComputerSecurityStudent (CSS) [Login] [Join Now]




|UNIX >> CentOS >> CentOS-6.6 >> Current Page |Views: 24047

(CentOS 6.6: Lesson 6)

{ Basic whoami, ls, cat, more, mkdir, cp, mv, rm Commands Usage }


Section 0. Background Information
  1. Background Information
    • In this lesson, you will be exposed to some very common and popular commands to help you navigate around in the Linux world via a command line.

  2. Pre-requisites
    1. CentOS 6.6: Lesson 1: Installing CentOS 6.6

  3. Lab Notes
    • In this lab we will do the following:
      1. Determine who the current user is after switching user.
      2. Determine who the current user was before switching user.
      3. Learning how to create, rename and delete files.
      4. Learning how to view files.

  4. Legal Disclaimer
    • As a condition of your use of this Web site, you warrant to computersecuritystudent.com that you will not use this Web site for any purpose that is unlawful or that is prohibited by these terms, conditions, and notices.
    • In accordance with UCC § 2-316, this product is provided with "no warranties, either express or implied." The information contained is provided "as-is", with "no guarantee of merchantability."
    • In addition, this is a teaching website that does not condone malicious behavior of any kind.
    • You are on notice, that continuing and/or using this lab outside your "own" test environment is considered malicious and is against the law.
    • © 2015 No content replication of any kind is allowed without express written permission.

 
Section 1. Configure CentOS-6.6 Virtual Machine Settings

  1. Open Your VMware Player
    • Instructions:
      1. On Your Host Computer, Go To
      2. Start --> All Program --> VMWare --> VMWare Player
     
  2. Edit CentOS-6.6 Virtual Machine Settings
    • Instructions:
      1. Highlight CentOS-6.6
      2. Click Edit virtual machine settings

     

  3. Auto Detect Hard Drive
    • Instructions:
      1. Click on CD/DVD(IDE)
      2. Click the Use physical drive: radio button
      3. Make sure Auto detect is selected

     

  4. Edit Network Adapter
    • Instructions:
      1. Highlight Network Adapter
      2. Select Bridged
      3. Click the OK Button

 

Section 2. Play Virtual Machine
  1. Start the CentOS-6.6 VM
    • Instructions:
      1. Click on the CentOS-6.6 VM
      2. Click on Play virtual machine
     

 

Section 3. Login to CentOS
  1. Login to CentOS
    • Note(FYI):
      1. Until you click the user, in this case Security Student, the Password field will not be displayed.
    • Instructions:
      1. Click on Security Student
        • This will display the password text box.
      2. Supply its' password
      3. Click the Log In Button
     
  2. Open a Terminal
    • Instructions:
      1. Applications --> System Tools --> Terminal

     

  3. Switch User to root
    • Instruction:
      1. su - root
      2. Supply the Root Password
    • Notes (FYI):
      1. su - root, this command allows the user student to switch user to user root, provided the root password can be supplied.

     

  4. Get IP Address
    • Instructions:
      1. ifconfig -a
    • Notes (FYI):
      • As indicated below, my IP address is 192.168.1.101 for Network Interface eth1.
        • Please record your IP address
      • The Local Loopback Address is 127.0.0.1 for Network Interface lo.
        • The loopback device is a special, virtual network interface that your computer uses to communicate with itself.  When the network or wifi is disconnected the loopback exists so applications running on your computer can always connect to servers on the same machine.

 

Section 4. Who Am I and Who Was I?
  1. Who Am I -and- Who Was I?
    • Instructions:
      1. whoami
      2. ps -f
        • Obtain the PPID associated with the line that contains "su - root".  My PPID is 30234.  Record your PPID.
      3. ps -eaf | grep 30234 | grep -v grep
      4. who am i
    • Note(FYI):
      1. whoami, this command displays the user name associated with the current effective user ID.
      2. ps -f, this command display processes.  Using the ps command without using the all (-ea) option, will only display the process for the current effective user.  The (-f) option will display a full listing.
      3. ps -eaf | grep 30234 | grep -v grep
        • ps -eaf, will display all the systems running processes.
        • grep 30234, will search for only current PID and parent PPID processes that contain the string 30234.
        • grep -v grep, use (-v) to ignore a process line with grep in it.
        • Notice the current process (PID) associated with 30234 is the student's bash shell, which is created during the login process.
      4. who am i, will display the original logged in user.  Notice the user is student.

 

Section 5. Directory Navigation
  1. Moving Up and Down a Directory Tree
    • Instructions:
      1. cd /etc/sysconfig/network-scripts
      2. pwd
      3. cd ../
      4. cd ../../
      5. pwd
    • Note(FYI):
      1. Change directory to the /etc/sysconfig/network-scripts directory.  Notice network-scripts is three directories down.
        • /etc - First level directory
        • /etc/sysconfig - Second level directory
        • /etc/sysconfig/network-scripts - Third level directory
      2. pwd, display current working directory.
      3. cd ../, change directory one level up from /etc/sysconfig/network-scripts to /etc/sysconfig.
      4. pwd, display current working directory.
      5. cd ../../, change directory two level up from /etc/sysconfig to /.
      6. pwd, display current working directory.

     

  2. Go Back To Previous Directory
    • Instructions:
      1. cd /home/student
      2. pwd
      3. cd /etc/sysconfig/network-scripts
      4. pwd
      5. cd -
    • Note(FYI):
      1. Change directory to the /home/student directory. 
      2. pwd, display current working directory.
      3. Change directory to the /etc/sysconfig/network-scripts directory. 
      4. pwd, display current working directory.
      5. cd -, Go back to the previous directory.

     

  3. Go To Current User's home directory
    • Instructions:
      1. cd /
      2. pwd
      3. whoami
      4. grep "^root" /etc/passwd
      5. cd ~
      6. pwd
    • Note(FYI):
      1. Change directory to the / directory. 
      2. pwd, display current working directory.
      3. whoami, this command displays the user name associated with the current effective user ID.
      4. grep "^root" /etc/passwd, Search the /etc/passwd file for line in the file that starts with (^) the string "root".
      5. Change directory to the /etc/sysconfig/network-scripts directory. 
      6. pwd, display current working directory.
      7. cd ~, Go to current user's home directory.  The currently user is root.  User root's home directory is located in "/root".

 

Section 6. Basic Linux File Types
  1. Creating File Types
    • Instructions:
      1. mkdir -p /var/tmp/etc/passwd_dir
      2. cd /var/tmp/etc
      3. ln -s /etc/passwd passwd_link
      4. cp /etc/passwd passwd_file
      5. cp passwd_file .passwd_hidden_file
      6. ls -la
    • Note(FYI):
      1. mkdir, this command create a directory.  The "-p" option will create any directories that don't already exist.
      2. Change Directory into the /var/tmp/etc directory.
      3. Create a softlink or short cut, called passwd_link to the /etc/passwd.
      4. Copy the /etc/passwd file and name it passwd_file
      5. Make another copy of the passwd_file and name it .passwd_hidden_file. In Linux, a file starting with a period(.) makes it invisible to a regular file listing.
      6. ls -la, The ls command list directory contents.  The "-l" option provides a long listing format.  The "-a" will display invisible files starting with period(.).  

     

  2. Listing Visible and Invisible Files
    • Instructions:
      1. ls -l
      2. ls -la
    • Note(FYI):
      1. ls -l, This command displays a long listing of the visible files.  Notice, you cannot see the .passwd_hidden_file.
      2. ls -la, This command displays a long listing of both visible and invisible files.
        1. passwd_dir, is a directory.  Notice the permissions (drwxr-xr-x) start with a "d" that indicates the file is actually a directory.
        2. passwd_file, is a file.  The permissions (-rw-r--r--)start with a "-", which indicates a file.
        3. .passwd_hidden_file, is also a file, but since it starts with a ".", it is not visible to a regular file listing.
        4. passwd_link, is a symbolic link.  The permissions (lrwxrwxrwx) start with a "l", which indicates a link.

     

  3. Determine File Types
    • Instructions:
      1. file /var/tmp/etc/passwd_file
      2. file /var/tmp/etc/passwd_link
      3. file /var/tmp/etc/passwd_dir/
      4. file /usr/bin/perl
    • Note(FYI):
      1. file, is a command used to determine file types.
        • /var/tmp/etc/passwd_file - ASCII text
        • /var/tmp/etc/passwd_link - Symbolic link
        • /var/tmp/etc/passwd_dir/ - Directory
        • /usr/bin/perl - Executable

     

  4. Listing All Directory Contents
    • Instructions:
      1. ls -alR /var/tmp/etc/
      2. find /var/tmp/etc/ -print
    • Note(FYI):
      1. ls -alR /var/tmp/etc/, Recursively(R) long list(l) all(a) the contents of the /var/tmp/etc/ directory.  Notice that after all the immediate directories and files have been listed, then all the files located in /var/tmp/etc/passwd_dir are listed.
      2. find /var/tmp/etc/ -print, The find command is used in the same fashion to list all the files in /var/tmp/etc.  Notice it is a cleaner looking list that could better be used in a program.

 

Section 7. Display File Contents
  1. Using the cat command (Print Output)
    • Instructions:
      1. cat /var/tmp/etc/passwd_file
    • Note(FYI):
      1. cat, this command can be used for (1) concatenating files and (2)printing output to the screen.  In this case, we are using it to just display the contents of a file.

     

  2. Using the cat command (File Creation)
    • Instructions:
      1. cat /var/tmp/etc/passwd_file > /var/tmp/etc/passwd_file2
      2. ls -l /var/tmp/etc/passwd_file*
      3. md5sum /var/tmp/etc/passwd_file*
    • Note(FYI):
      1. (cat /var/tmp/etc/passwd_file) will display file contents to the screen. The the greater than/redirect operator (>) will redirect the content into another file called /var/tmp/etc/passwd_file2.
      2. (ls -l /var/tmp/etc/passwd_file*), will display all the files starting with the string passwd_file in the /var/tmp/etc directory.
      3. (md5sum /var/tmp/etc/passwd_file*) will display all the MD5 checksums for all the files starting with the string passwd_file.

     

  3. Using the more command
    • Instructions:
      1. more /var/tmp/etc/passwd_file
      2. Press <Enter> until off the contents of the file is displayed.
    • Note(FYI):
      1. more, is a command that is used to page through text one screenful at a time.

 

Section 8. Display File Contents
  1. Opening a file with VI
    • Instructions:
      1. vi /var/tmp/etc/passwd_file
    • Note(FYI):
      1. vi is a plain text editor.

     

  2. Save and Exit VI
    • Instructions:
      1. Press the <Esc> button
      2. Type :wq!

     

  3. Opening a file with gedit
    • Instructions:
      1. gedit /var/tmp/etc/passwd_file 2>/dev/null
      2. Click "X" to close gedit
    • Note(FYI):
      1. gedit, is the gnome text editor.

     

Section 9. Copying, Moving and Deleting Files
  1. Opening a file with gedit
    • Instructions:
      1. cd /var/tmp/etc
      2. ls -l
      3. cp passwd_file2 passwd_file4
      4. mv passwd_file4 passwd_file3
      5. ls -l
    • Note(FYI):
      1. cd /var/tmp/etc, Change directory into /var/tmp/etc.
      2. ls -l, List the files in the /var/tmp/etc directory.
      3. cp passwd_file2 passwd_file4, use the copy command (cp) to copy file passwd_file2 and name the new file passwd_file4.
      4. mv passwd_file4 passwd_file3, use the move/rename command (mv)to rename passwd_file4 to passwd_file3.
      5. ls -l, List the files in the /var/tmp/etc directory.
     
  2. Opening a file with gedit
    • Instructions:
      1. cp passwd_file3 passwd_file5
      2. ls -l passwd_file*
      3. rm passwd_file5
      4. y
      5. ls -l passwd_file*
    • Note(FYI):
      1. cp passwd_file3 passwd_file5, use the copy command (cp) to copy file passwd_file3 and name the new file passwd_file5.
      2. ls -l passwd_file*, In the /var/tmp/etc directory, list all the files that start with the string passwd_file.  The asterisk(*) is a wild card.
      3. rm passwd_file5, use the remove/delete command (rm)to delete the passwd_file5 file.
      4. If you do not use the (-f) option with the rm command, then you will prompted to re-verify the deletion of a file.
      5. See comment #2.

     

Section 10. Proof of Lab
  1. Proof of Lab
    • Instructions:
      1. find /var/tmp/etc/ -print | xargs ls -lad
      2. date
      3. echo "Your Name"
        • Put in your actual name in place of "Your Name"
        • e.g., echo "John Gray"
    • Note(FYI):
      1. find /var/tmp/etc/ -print | xargs ls -lad
        • Use (find /var/tmp/etc/ -print)to display all the file in the /var/tmp/etc directory.
        • Use (xargs ls -lad) to display the long listing of both visible and invisible files.
    • Proof of Lab Instructions
      1. Press the <Ctrl> and <Alt> key at the same time.
      2. Press the <PrtScn> key.
      3. Paste into a word document
      4. Upload to Moodle


Help ComputerSecurityStudent
pay for continued research,
resources & bandwidth