Sign inSign up

marlabsdocker/lesson3

By marlabsdocker

•Updated almost 9 years ago

Introduction to Linux. Lesson 3. Moving a user and its home directory. Lab.

Image
0

357

marlabsdocker/lesson3 repository overview

++++++++++++++++++++++++++++++++++++++++++

⁠MOVING A USER AND ITS HOME DIRECTORY

⁠+++++++++++++++++++++++++++++++++++++++++++++

This section will demonstrate how to put together some of the topics and utilities covered so far in this chapter. The elegant design of Linux allows you to combine simple commands to perform advanced operations. Sometimes in the course of administration you might have to move a user and its files around. This section will cover the process of moving a user’s home directory. In this section, you are going to move the user named “project5” from his default home directory /home/project5 to /export/home/project5. You will also have to set the proper permissions and ownership of the user’s files and directories so that the user can access it. Unlike the previous exercises, which were performed as a regular user (the user yyang), you will need superuser privileges to perform the steps in this exercise.

  1. Log into the system as root and launch a virtual terminal.
  2. Create the user that will be used for this project. The username is “project5.” Type [root@fedora-serverA ~]# useradd project5
  3. Use the grep command to view the entry for the user you created in the /etc/ passwd file. Type [root@fedora-serverA ~]# grep project5 /etc/passwd project5:x:502:503::/home/project5:/bin/bash
  4. Use the ls command to display a listing of the user’s home directory. Type [root@fedora-serverA ~]# ls -al /home/project5 total 48 drwx------ 3 project5 project5 4096 2010-10-08 13:12 . drwxr-xr-x 7 root root 4096 2010-10-08 13:12 .. -rw-r--r-- 1 project5 project5 33 2010-10-08 13:12 .bash_logout -rw-r--r-- 1 project5 project5 176 2010-10-08 13:12 .bash_profile -rw-r--r-- 1 project5 project5 124 2010-10-08 13:12 .bashrc
  5. Check the total disk space being used by the user. Type [root@fedora-serverA ~]# du -sh /home/project5 56K /home/project5
  6. Use the su command to temporarily become the user. Type [root@fedora-serverA ~]# su - project5 [project5@fedora-serverA ~]$
  7. As user project5, view your present working directory. Type [project5@fedora-serverA ~]$ pwd /home/project5
  8. As user project5, create some empty files. Type [project5@fedora-serverA ~]$ touch a b c d e
  9. Go back to being the root user by exiting out of project5’s profile. Type [project5@fedora-serverA ~]$ exit
  10. Create the /export directory that will house the user’s new home. Type [root@fedora-serverA ~]# mkdir -p /export
  11. Now use the tar command to archive and compress project5’s current home directory (/home/project5) and untar and decompress it into its new location. Type [root@fedora-serverA ~]# tar czf - /home/project5 | (cd /export ; tar -xvzf -)

TIP The dashes (-) you used here with the tar command force it to first send its output to stdout and then receive its input from stdin. 12. Use the ls command to ensure that the new home directory was properly created under the /export directory. Type [root@fedora-serverA ~]# ls -R /export/home/ /export/home/: project5 /export/home/project5: a b c d e 13. Make sure that project5 has complete ownership of all the files and directories in its new home. Type [root@fedora-serverA ~]# chown -R project5.project5 /export/home/project5/ 14. Now delete project5’s old home directory. Type [root@fedora-serverA ~]# rm -rf /home/project5 15. Good, we are almost done. Try to temporarily assume the identity of project5 again. Type [root@fedora-serverA ~]# su - project5 su: warning: cannot change directory to /home/project5: No such file or directory -bash-3.2$ Ah… one more thing left to do. We have deleted the user’s home directory (/home/project5), as was specified in the /etc/passwd file, and that is why the su command complained. 16. Exit out of project5’s profile using the exit command. Type -bash-3.00$ exit 17. Now we’ll use the usermod command to automatically update the /etc/passwd file with the user’s new home directory. Type [root@fedora-serverA ~]# usermod -d /export/home/project5 project5 NOTE On a system with SELinux enabled, you might get a warning about not being able to relabel the home directory. You can ignore this warning for now.

  1. Use the su command again to temporarily become project5. Type [root@fedora-serverA ~]# su - project5 [project5@fedora-serverA ~]$
  2. While logged in as project5, use the pwd command to view your present working directory. Type [project5@fedora-serverA ~]$ pwd /export/home/project5 This output shows that our migration worked out well.
  3. Exit out of project5’s profile to become the root user, and then delete the user called project5 from the system. Type [root@fedora-serverA ~]# userdel -r project5

Tag summary

Content type

Image

Digest

Size

91 MB

Last updated

almost 9 years ago

docker pull marlabsdocker/lesson3