Bookmark this page

Lab: Working with a Linux System

Identify the characteristics of a Linux system, obtain software, and manage system resources.

Outcomes

  • Set up SSH key-based authentication.

  • Collect system information.

  • Manage services and processes.

  • Install software packages.

If you did not reset your workstation and server machines at the end of the last chapter, then save any work you want to keep from earlier exercises on those machines, and reset them now.

As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.

[student@workstation ~]$ lab start compreview-review2

In this exercise, you create some files on the servera machine. Make sure to use the exact file names from the exercise and create the files in the /home/student directory.

The Solution section for this lab displays command-line steps for each specification, but you can use graphical or command-line tools to perform the required tasks.

To work on this comprehensive review lab, imagine the following scenarios.

You start a new project and must use the servera Linux computer to do your work. Gather system information to share with the Information Security team so that they can allow your computer onto the network.

You must also prepare the new machine to run some applications. The applications depend on the servera machine time configuration and a programming interpreter. You must also optimize the computer resources so that you can work without performance issues.

Specifications

  • Your team configured the developer1 user on the servera machine for you to perform some tasks. You will constantly log in from the workstation machine to the servera machine as the developer1 user. To avoid entering redhat as the password every time you log in, set up SSH key-based authentication.

  • The Information Security team asked you to provide system information to identify the servera machine and to allow you to access the network. The Information Security team requested the following system information: hostname, IP address, total size of the file system in GB, system memory size in MB, and the time zone. As the student user, provide the information in the following format:

    Hostname: web22.example.com
    IP: 172.32.8.1/28
    Disk: 11.2G
    Memory: 2890M
    Timezone: CET

    Save the information in the ~/sysinfo.txt file on the workstation and servera machines.

  • As the student user, prepare the servera machine to run some organization applications. Make sure that the chronyd time synchronization service is running, and is configured to start automatically during system boot. Also, install the Ruby programming language interpreter. Save the Ruby interpreter version information to the ~/ruby-version.txt file to share it and to ensure that the package is compatible with the applications.

  • You notice that the servera machine performs poorly when you open any application. The IT Support team recommends that you monitor the system resources to find a possible crashed application. Find any application that is using a high level of CPU resources and terminate it.

  1. As the developer1 user on the workstation machine, set up SSH key-based authentication to log in to the servera machine as the developer1 user without having to type a password. Use redhat as the password for the developer1 user.

    1. On the workstation machine, switch to an unused virtual console by pressing the Ctrl+Alt+F3 combination. Log in as the developer1 user.

      Red{nbsp}Hat Enterprise Linux 9.1 (Plow)
      Kernel 5.14.0-162.6.1.el9_1x86_64 on an x86_64
      
      Activate the web console with: systemctl enable --now cockpit.socket
      workstation login: developer1
      Password: redhat
      [developer1@workstation ~]$
    2. Verify that you can log in to the servera machine. After logging in, exit the servera machine.

      [developer1@workstation ~]$ ssh developer1@servera
      ...output omitted...
      Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
      Warning: Permanently added 'servera' (ED25519) to the list of known hosts.
      developer1@servera's password: redhat
      [developer1@servera ~]$ exit
      logout
      Connection to servera closed.
    3. Create an SSH key pair on the workstation machine. Do not configure a passphrase for the key pair.

      [developer1@workstation ~]$ ssh-keygen
      Generating public/private rsa key pair.
      Enter file in which to save the key (/home/developer1/.ssh/id_rsa): Enter
      Enter passphrase (empty for no passphrase): Enter
      Enter same passphrase again: Enter
      Your identification has been saved in /home/developer1/.ssh/id_rsa
      Your public key has been saved in /home/developer1/.ssh/id_rsa.pub
      ...output omitted...
    4. Set up SSH key-based authentication by copying the developer1 public key to the servera machine.

      [developer1@workstation ~]$ ssh-copy-id developer1@servera
      ...output omitted...
      developer1@servera's password: redhat
      
      Number of key(s) added: 1
      
      Now try logging into the machine, with:   "ssh 'developer1@servera'"
      and check to make sure that only the key(s) you wanted were added.
    5. Verify that you can log in to the servera machine as the developer1 user without typing a password. After logging in, exit the servera machine and switch to the previous virtual console.

      [developer1@workstation ~]$ ssh developer1@servera
      [developer1@servera ~]$ exit
      logout
      Connection to servera closed.
      [developer1@workstation ~]$ exit

      Switch to the second virtual console by pressing the Ctrl+Alt+F2 combination.

  2. As the student user on the servera machine, collect information about the local system. Create the sysinfo.txt file and save the following system information: hostname, IP address, total size of the file system in GB, system memory size in MB, and the time zone. The following sample demonstrates the required format:

    [student@workstation ~]$ cat sysinfo.txt
    Hostname: web22.example.com
    IP: 172.32.8.1/28
    Disk: 11.2G
    Memory: 2890M
    Timezone: CET

    When completed, copy the sysinfo.txt file to the home directory of the student user on the workstation machine.

    1. Log in to the servera machine. Print the hostname of the system.

      [student@workstation ~]$ ssh student@servera
      student@servera's password: student
      ...output omitted...
      [student@servera ~]$ hostname
      servera.lab.example.com

      The hostname is servera.lab.example.com. Add the information to the sysinfo.txt file.

      [student@servera ~]$ echo "Hostname: servera.lab.example.com" > sysinfo.txt
    2. Print the IP address of the system. The IP address is defined in the eth0 interface.

      [student@servera ~]$ ip addr
      1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
      ...output omitted...
      2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
      ...output omitted...
          inet 172.25.250.10/24 brd 172.25.250.255 scope global noprefixroute eth0
             valid_lft forever preferred_lft forever
          inet6 fe80::5054:ff:fe00:fa0a/64 scope link
             valid_lft forever preferred_lft forever

      The IP address of the computer is 172.25.250.10/24. Add the information to the sysinfo.txt file.

      [student@servera ~]$ echo "IP: 172.25.250.10/24" >> sysinfo.txt
    3. Print the total size of the file system.

      [student@servera ~]$ df -h /
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/vda4       9.4G  1.8G  7.6G  19% /

      The total file system size is 9.4 GB. Add the information to the sysinfo.txt file.

      [student@servera ~]$ echo "Disk: 9.4GB" >> sysinfo.txt
    4. Print the system's memory size.

      [student@servera ~]$ free -m
                     total        used        free      shared  buff/cache   available
      Mem:            1770         425        1261          10         277        1345
      Swap:              0           0           0

      The total installed memory size is 1770 MB. Add the information to the sysinfo.txt file.

      [student@servera ~]$ echo "Memory: 1770MB" >> sysinfo.txt
    5. Print the time zone that is configured on the system.

      [student@servera ~]$ timedatectl
                     Local time: Sun 2023-12-03 17:35:26 EST
                 Universal time: Sun 2023-12-03 22:35:26 UTC
                       RTC time: Sun 2023-12-03 22:35:26
                      Time zone: America/New_York (EST, -0500)
      System clock synchronized: no
                    NTP service: inactive
                RTC in local TZ: no

      The servera machine's time zone is Eastern Standard Time (EST). Add the information to the sysinfo.txt file.

      [student@servera ~]$ echo "Timezone: EST" >> sysinfo.txt
    6. Verify the contents of the sysinfo.txt file.

      [student@servera ~]$ cat sysinfo.txt
      Hostname: servera.lab.example.com
      IP: 172.25.250.10/24
      Disk: 9.4GB
      Memory: 1770MB
      Timezone: EST
    7. Copy the sysinfo.txt file to the home directory of the student user on the workstation machine.

      [student@servera ~]$ scp sysinfo.txt student@workstation:~/
      ...output omitted...
      Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
      Warning: Permanently added 'workstation' (ED25519) to the list of known hosts.
      student@workstation's password: student
      sysinfo.txt                                         100%   95   342.7KB/s   00:00
  3. Make sure that the chronyd time synchronization service is running, and is configured to start automatically during system boot.

    1. Verify the status of the chronyd service.

      [student@servera ~]$ systemctl status chronyd
      ○ chronyd.service - NTP client/server
           Loaded: loaded (/usr/lib/systemd/system/chronyd.service; disabled; vendor preset: enabled)
           Active: inactive (dead)
             Docs: man:chronyd(8)
                   man:chrony.conf(5)
      
      ...output omitted...

      The service is stopped and disabled. This configuration prevents the service from starting during system boot.

    2. Start and enable the service to ensure that it always starts during boot. Use your sudo privilege with the systemctl command to start the chronyd service.

      [student@servera ~]$ sudo systemctl enable --now chronyd.service
      [sudo] password for student: student
      Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service
      [student@servera ~]$ systemctl status chronyd.service
      ● chronyd.service - NTP client/server
           Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
           Active: active (running) since Fri 2023-11-24 10:25:44 EST; 11s ago
             Docs: man:chronyd(8)
                   man:chrony.conf(5)
          Process: 3620 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
         Main PID: 3622 (chronyd)
            Tasks: 1 (limit: 10666)
           Memory: 836.0K
              CPU: 29ms
      ...output omitted...
  4. Install the Ruby programming language interpreter. Save the Ruby interpreter version information to the ruby-version.txt file.

    1. Search for the Ruby programming language interpreter.

      [student@servera ~]$ dnf search ruby
      Red Hat Enterprise Linux 9.1 BaseOS (dvd)             9.7 MB/s | 1.7 MB     00:00
      Red Hat Enterprise Linux 9.1 AppStream (dvd)           28 MB/s | 6.1 MB     00:00
      ================================ Name Exactly Matched: ruby ========================================
      ruby.i686 : An interpreter of object-oriented scripting language
      ruby.x86_64 : An interpreter of object-oriented scripting language
      =============================== Name & Summary Matched: ruby =======================================
      libselinux-ruby.x86_64 : SELinux ruby bindings for libselinux
      ruby-default-gems.noarch : Default gems which are part of Ruby StdLib
      ruby-devel.i686 : A Ruby development environment
      ruby-devel.x86_64 : A Ruby development environment
      ...output omitted...

      The ruby package matches the description.

    2. Install the ruby package. Use your sudo privilege with the dnf command and use student as the password.

      [student@servera ~]$ sudo dnf install ruby
      [sudo] password for student: student
      ...output omitted...
      Installing:
       ruby     x86_64  3.0.4-160.el9_0  rhel-9.1-for-x86_64-appstream-rpms    45 k
      ...output omitted...
      Is this ok [y/N]: y
      ...output omitted...
      Complete!
    3. Save the Ruby interpreter version information to the ruby-version.txt file.

      [student@servera ~]$ ruby --version > ruby-version.txt
      [student@servera ~]$ cat ruby-version.txt
      ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
  5. Find the student user process that is causing high CPU usage. Identify the PID that is associated with the process, and terminate the process to free up system resources.

    1. Use the top command to monitor the system's resource usage. Search for the process that is using a high level of CPU resources to run.

      top - 20:14:03 up  4:40,  1 user,  load average: 0.97, 0.75, 1.54
      Tasks: 144 total,   2 running, 142 sleeping,   0 stopped,   0 zombie
      %Cpu(s):  0.2 us,  1.8 sy, 48.1 ni, 49.8 id,  0.0 wa,  0.2 hi,  0.0 si,  0.0 st
      MiB Mem :   1770.8 total,   1116.4 free,    416.6 used,    431.2 buff/cache
      MiB Swap:      0.0 total,      0.0 free,      0.0 used.   1354.2 avail Mem
      
          PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
        27245 student   22   2  225744   2248   1796 R 100.0   0.1   3:16.74 md5sum
      ...output omitted...

      The md5sum process is using nearly 100% of the CPU for a prolonged time. The PID of the md5sum process is 27245.

      The ID of the md5sum process might be different in your system.

    2. Terminate the md5sum process. On the top command interface, press k and verify that the suggested PID matches the process that you intend to terminate.

      top - 20:14:03 up  4:40,  1 user,  load average: 0.97, 0.75, 1.54
      Tasks: 144 total,   2 running, 142 sleeping,   0 stopped,   0 zombie
      %Cpu(s):  0.2 us,  1.8 sy, 48.1 ni, 49.8 id,  0.0 wa,  0.2 hi,  0.0 si,  0.0 st
      MiB Mem :   1770.8 total,   1116.4 free,    416.6 used,    431.2 buff/cache
      MiB Swap:      0.0 total,      0.0 free,      0.0 used.   1354.2 avail Mem
      PID to signal/kill [default pid = 27245]
          PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
        27245 student   22   2  225744   2248   1796 R 100.0   0.1   3:16.74 md5sum

      Press Enter to confirm the PID to terminate, and press Enter again to confirm the default signal to terminate the process.

      top - 20:14:03 up  4:40,  1 user,  load average: 0.97, 0.75, 1.54
      Tasks: 144 total,   2 running, 142 sleeping,   0 stopped,   0 zombie
      %Cpu(s):  0.2 us,  1.8 sy, 48.1 ni, 49.8 id,  0.0 wa,  0.2 hi,  0.0 si,  0.0 st
      MiB Mem :   1770.8 total,   1116.4 free,    416.6 used,    431.2 buff/cache
      MiB Swap:      0.0 total,      0.0 free,      0.0 used.   1354.2 avail Mem
      Send pid 1305 signal [15/sigterm]
          PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
        27245 student   22   2  225744   2248   1796 R 100.0   0.1   3:16.74 md5sum
    3. Verify that the md5sum process is no longer running.

      top - 20:14:03 up  4:40,  1 user,  load average: 0.97, 0.75, 1.54
      Tasks: 144 total,   2 running, 142 sleeping,   0 stopped,   0 zombie
      %Cpu(s):  0.2 us,  1.8 sy, 48.1 ni, 49.8 id,  0.0 wa,  0.2 hi,  0.0 si,  0.0 st
      MiB Mem :   1770.8 total,   1116.4 free,    416.6 used,    431.2 buff/cache
      MiB Swap:      0.0 total,      0.0 free,      0.0 used.   1354.2 avail Mem
      
          PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
            1 root      20   0  173004  17004  10300 S   0.0   0.9   0:02.52 systemd
            2 root      20   0       0      0      0 S   0.0   0.0   0:00.01 kthreadd
            3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp

      Alternatively, use the pgrep command to search for the md5sum process. As expected, searching for the process returns no output.

      [student@servera ~]$ pgrep -f md5sum
    4. Exit from the servera machine.

      [student@servera ~]$ exit
      logout
      Connection to servera closed.

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade compreview-review2

Finish

On the workstation machine, change to the student user home directory and 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 compreview-review2
Revision: rh104-9.1-3d1f2bc