Bookmark this page

Guided Exercise: Using the Command Line

Access the Linux shell by using a virtual console or terminal application, and learn commands to gather information about a Linux system.

Outcomes

  • Log in to a Linux shell.

  • Use non-interactive commands to view information about a Linux system.

  • Modify a user's password.

As the student user on the workstation machine, open a terminal. You can open a terminal by clicking Activities and then Terminal.

On the command line, use the following lab command to prepare your system for this exercise, and to ensure that all required resources are available.

[student@workstation ~]$ lab start access-cli

Instructions

  1. View information about your login session:

    [student@workstation ~]$ who
    student  pts/0        2023-09-27 22:01 (172.25.250.254)
  2. View the current date, time, and time zone:

    [student@workstation ~]$ timedatectl
                   Local time: Wed 2023-09-27 22:01:46 EDT
               Universal time: Thu 2023-09-28 02:01:46 UTC
                     RTC time: Thu 2023-09-28 02:01:46
                    Time zone: America/New_York (EDT, -0400)
    System clock synchronized: yes
                  NTP service: active
              RTC in local TZ: no
  3. View the machine name:

    [student@workstation ~]$ hostname
    workstation.lab.example.com
  4. Review the information about the operating system, kernel, and hardware. Use the tab completion feature to run the hostnamectl command.

    Type hostn and then press Tab. The shell completes the hostname command, but this is not the intended command. Review the suggestions by pressing Tab twice, type c, and press Tab again. Then run the command.

    [student@workstation ~]$ hostnTab
    [student@workstation ~]$ hostnameTab+Tab
    hostname     hostnamectl
    [student@workstation ~]$ hostnamecTab
    [student@workstation ~]$ hostnamectl
     Static hostname: workstation.lab.example.com
           Icon name: computer-vm
             Chassis: vm
          Machine ID: 633680e38e32491899fbd3a7f6129842
             Boot ID: f97b2fbc043a4de7803a4e8b46d3ac33
      Virtualization: kvm
    Operating System: Red Hat Enterprise Linux 9.0 (Plow)
         CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos
              Kernel: Linux 5.14.0-70.13.1.el9_0.x86_64
        Architecture: x86-64
     Hardware Vendor: Red Hat
      Hardware Model: OpenStack Compute

    Most of this information is the same as the information shown in the About section of the GNOME control panel.

  5. On the third virtual console, log in as the operator2 user and use redhat as the password. Update the user's password to rh104.cli.

    1. Switch to the third virtual console by pressing Alt+Ctrl+F3. Log in as the operator2 user and use redhat as the password.

    2. Review the passwd command help. The --help (or -h) option prints information about the command itself, including the options you can use to alter the command's outcome.

      [operator2@workstation ~]$ passwd --help
      Usage: passwd [OPTION...] <accountName>
        -k, --keep-tokens       keep non-expired authentication tokens
        -d, --delete            delete the password for the named account (root only); also removes password lock if any
        -l, --lock              lock the password for the named account (root only)
        -u, --unlock            unlock the password for the named account (root only)
      ...output omitted...
    3. Update the operator2 user password to rh104.cli.

      [operator2@workstation ~]$ passwd
      Changing password for user operator2.
      Current password: redhat
      New password: rh104.cli
      Retype new password: rh104.cli
      passwd: all authentication tokens updated successfully.
    4. Test the new password by closing the session and logging back in.

      [operator2@workstation ~]$ exit
      
      workstation login: operator2
      Password: rh104.cli
      [operator2@workstation ~]$
  6. Close the virtual console session and return to the desktop session.

    1. Close the virtual console session.

      [operator2@workstation ~]$ exit
    2. Return to the desktop session by pressing Alt+Ctrl+F2.

      $ Alt+Ctrl+F2

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish access-cli

Revision: rh104-9.1-3d1f2bc