sudo command examples

– It is a very useful tool to give the role based access to the users.

– Using sudo we can become other user for complete new session or we can get access to commands which are not generally accessed.

– We can give access to files for certain users.

– To list the present sudo status for the user

                # sudo -l
                # sudo -U santosh -l  (for specific user) 

  
– To long list the output

                # sudo –U santosh -ll 

  
– To remove users cached credentials

                # sudo -k 

  
– To get a file listing of an unreadable directory:

                # sudo ls /usr/local/protected 

  
– To view system logs only accessible to root and users in the adm group:

                # sudo -g adm view /var/log/syslog 

  
– To shut down a machine:

                # sudo shutdown -r +15 “quick reboot” 

  
– To run the command in background

                # sudo -b mount /dev/cdrom /DVD 

  
– To run the command as another user

                # sudo –u oracle /xyz/abc.sh 

  
– To execute the given command by setting the primary group to the given group

                # sudo –g DBA /xyz/abc.sh 

  
– To validate the user credentials


     # sudo –v                 (updates his cached credentials, like if password has been changed) 

Leave a Reply

Your email address will not be published. Required fields are marked *