How to give the user sudo privilege?

Scenario: Create two users 'tom' and 'cat'. 'tom' must have sudo privilege whereas 'cat' has normal privilege. Also, a file created by 'tom' is editable by 'cat'. 'tom' must have a home directory /home/tom but the 'cat' should not have a home directory.

  1. Switch to root user:

     sudo su
    
  2. Create users ‘tom’ and ‘cat’ as

     adduser tom
     adduser cat
     tail -n 5 /etc/passwd
    

  3. Add sudo privilege configuration for user tom

     sudo visudo
    

    Save and exit.

  4. Now remove the default created home directory of 'cat' user so that 'cat' user should not have any home directory using the root user

     sudo rm -rf cat
     su cat
     cd
     ls
    

  1. Now create a file using user 'tom'

     su tom
     cat > hello.txt
    

Change ownership so that cat user can access the current folder and content.

sudo chown cat .
su cat

So we can access and edit it from cat user

nano hello.txt
cat hello.txt

Now we are able to access files and folders inside /home/tom with cat user also.