Thursday, September 26, 2024

Linux: Add user to sudo List

To do this, we need to edit the /etc/sudoers file. Never edit the sudoers filein a normal text editor. This could lead to simultaneous editing and corrupt files. We can edit the sudoers files by using the visudo command. sudo visudo Press Shift+G to navigate to the bottom of the document. Press the letter “i” onyour keyboard to begin editing the document. Create a new line at the bottom ofthe document and add the following text. Defaults timestamp_timeout=1800 This will set your sudo timeout to 1800 seconds (30 minutes), so you will have sudo permissions for 30 minutes after you execute the first command. If you prefer a different interval, enter that value in seconds instead. You will then want to navigate up in the document to this snippet of text. Underneath where it says root, paste this snippet of text. myuserid ALL=(ALL) ALL This snippet of text will give myuserid root privileges. Once you complete this task, hit the ESC button, scroll down to the bottom of the document and type the following text. Then, hit enter. :wq This sequence will save the file and exit the editor. We now need to switch users so that we are working under myuserid and not opc. We can do this by running this command. su - myuserid We have now granted sudo privileges to myuserid.