Bookmark this page

Lab: Edit a System File with vim

In this lab, you will create and edit a new system file using vim.

Resources
Files: /etc/motd
Machines: desktopX

Outcomes

An updated /etc/motd file on desktopX.

N/A

You have been asked to update the Message-Of-The-Day (MOTD) file on desktopX. This file is called /etc/motd, and its contents are displayed to users upon a successful login on the command line.

  1. Update the /etc/motd file on desktopX to read exactly as it read in below text block without replacing the value of "X" in this step:

    desktopX.example.com
            
    Please be careful.
    1. Log into your desktopX system as student and open a terminal.

    2. Since /etc/motd is a system file, you will need to elevate your privileges.

      [student@desktopX ~]$ su -
      Password: redhat
    3. Open /etc/motd in vim.

      [root@desktopX ~]# vim /etc/motd
    4. Enter insert mode by pressing i or a, then type the following text:

      desktopX.example.com
                  
      Please be careful.
    5. Press Esc to exit insert mode and return to command mode, then type :wq to enter ex mode to save and quit.

  2. Test your changes by using ssh to connect to the student account on localhost. If all goes well, you should see your new message after authentication. Close the ssh connection when you are done testing.

    1. [root@desktopX ~]# ssh student@localhost
      The authenticity of host 'localhost (::1) can't be established.
      RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
      Are you sure you want to continue connecting (yes/no)? yes
      Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
      student@localhost's password: student
      desktopX.example.com
      
      Please be careful.
      [student@desktopX ~]$ exit
  3. Edit /etc/motd again. This time, replace the X in desktopX.example.com with your actual station number, using search and replace. You are also asked to repeat the Please be careful. line two more times.

    1. Open /etc/motd in vim. Make sure that you are still working as root.

      [root@desktopX ~]# vim /etc/motd
    2. Use search and replace to replace X with your actual station number. The example that follows assumes that you are station number 99.

      From command mode, enter ex mode and replace all occurrences of X with 99 by typing the following:

      :%s/X/99/g
    3. Move your cursor to line number three by typing the following from command mode:

      :3
    4. Yank (copy) the current line, then put (paste) it twice, by typing yy2p.

      The yy part yanks the current line, and 2p puts it twice.

    5. Save and quit by typing :wq.

  4. Test your changes by using ssh to connect to student@localhost again.

    1. [root@desktopX ~]# ssh student@localhost
      student@localhost's password: student
      desktop99.example.com
      
      Please be careful.
      Please be careful.
      Please be careful.
      [student@desktopX ~]$ exit
Revision: rh134-7-c643331