Logging in and using basic Linux Commands

Learn how to log in to Linux and use basic Linux commands, such as creating and deleting files, navigating the directory structure, and viewing system information.

Scenario: Begin exploring the use of Linux commands by logging in, changing your password, becoming superuser, using the cat command to view a file and the nano command to change a file.

instructions:

  1. This sequence will be run primarily from the first virtual console, tty1. Switch to the first virtual console by pressing: Ctrl-ALT-F1
  2. Log in as user student by entering student at the stationX: prompt and pressing return, and then entering the password student at the Password: prompt:
    stationX: student
    Password:
    [student@stationX ~] $


    Note that the password does not appear on the screen as you type it.
  3. Use the passwd command to set your password. When it asks for your current password. Enter student (as when logging in, the password will not appear when typed). Next, attempt to set a new, simple password, such as redhat:

    [student@stationX ~] $ passwd
    changing password for user student.
    changing password for student
    (current) UNIX password: student
    New UNIX password: redhat
    BAD PASSWORD: it is based on a dictionary word
    New UNIX password:


    Note that the password is rejected and you are prompted to enter a better password. The passwd command checks the strength of the password you enter to ensure that it is sufficiently difficult to guess.
  4. Try again , this time setting a complex password. Mix upper and lower case characters, use numbers and punctuation, and use at least eight characters. You will be prompted to re-enter the password. If you choose a sufficiently strong password and enter it exactly the same twice, you will succeed in changing your password and the output will look as follows:

    New UNIX password:
    Retype new UNIX password:
    passwd: all authentication tokens updated successfully.


    If your password is rejected, keep trying until you successfully change it.
  5. Log out by running the exit command:

    [student@stationX ~]$ exit

    Log in again, using your new password:

    stationX: student
    Password:
    [student@stationX ~]$

  6. You are now logged in as user student, a non-privileged user. For the next part of the lab, you will need superuser privileges to run the commands. Therefor, begin by becoming superuser, using the su command, and then when prompted for a password, enter redhat when prompted for it. Note that the dash (-) is given as an argument to the su command. In a later unit, this will be explained; for now, just be sure to provide the dash:

    [student@stationX ~]$ su -
    password:
    [root@stationX ~ ]#


    Note changes to the command prompt: the username displayed is now root and the final character in the prompt is a hash sign instead of a dollar sign. These are two visual indicators that you now have superuser privileges. From this point until you exit from the superuser shell, all commands you run will have full privileges. This means that it is vital that you double-check every command that you run, as some types of errors can render the system unusable.
  7. Use the passwd command to change the student account’s password back to student:

    [root@stationX ~]# passwd student
    changing password for user student.
    New UNIX password:
    BAD PASSWORD: it is based on a dictionary word
    Retype new UNIX password:
    passwd: all authentication tokens updated successfully.

  8. View the /etc/issue file, using the cat command:

    [root@stationX ~ ]# cat /etc/issue
    Red Hat Enterprise Linux Server release 5
    Kernel \r on an \m
    [root@stationX ~ ]#


    The /etc/issue file is displayed above the login prompt. The default content is shown above (minor variations are possible, depending on the version of the operating system and the current configuration). Common information to add is a warning to unauthorized persons to keep out.

    Note the \r and \m characters. These indicate the release level and machine architecture should be displayed. To confirm this, type Ctrl-Alt-F2 to see how these escaped characters (the backslash in this case is considered an escape, as it gives a special meaning to the next character) are converted.
  9. Type Ctrl-Alt-F1 to go to the first virtual console and then edit the /etc/issue file using the nano command:

    [root@stationX ~ ]# nano /etc/issue

    Take a moment to examine the nano screen. Note the blinking cursor, where text will be entered if you start typing. At the bottom of the page is a menu of actions that you can take. The caret (^) character indicates that you need to hold down the Ctrl key to take the action. For example,
    Ctrl-x will cause nano to exit.
  10. Add a new line at the top of /etc/issue to make it more friendly:

    Welcome !

    Save the changes by typing Ctrl-x. The nano command will ask if you want to save your changes (“Save modified buffer”). Enter y to save your changes.

    The nano command will suggest that you save to the /etc/issue file, which is what we intend; press Enter to confirm. This will save the file.
  11. Examine the file again. You should see something like this:

    [root@stationX ~ ]# cat /etc/issue
    Welcome !
    Red Hat Enterprise Linux Server release 5
    Kernel \r on an \m

    [root@stationX ~ ]#

  12. You can now check the effect of your changes, but alterations to /etc/issue do not take effect until your login prompts are restarted. A quick way to force the login prompts to reset themselves is to change to each of the login prompts from Ctrl-Alt-F2 to Ctrl-Alt-F6 and press Ctrl-d at each prompt. This will cause the login prompt to terminate and restart, rereading the /etc/issue file and displaying your new greeting.
  13. Clean up:

    Return to the first virtual console by typing Ctrl-Alt-F1.

    Type exit to exit out of the superuser shell. Note the change in your prompt.

    Type exit again to log out. The login prompt should return, including your new welcome message.

    Return to the graphical login by typing Ctrl-Alt-F7

Leave a Comment