Add a specific user to get sudo privilleges using shell scripts ONLY

superboy2k6

Member
Joined
Oct 23, 2019
Messages
32
Reaction score
9
Credits
0
Hey so I wanted to create a shell script so that a user is added in which the user has sudo privilleges. My code went like this:
Code:
#!/bin/bash
useradd liveuser ; echo -e "liveuser\nliveuser" | passwd liveuser
usermod -aG sudo liveuser
su liveuser
exit
It did create the user with the password but there was an issue. The CLI reported to me back that a group called sudo does not exist.
How to fix that? I don't want to manually add a user to the sudoers file.

Running Arch on a VM, freshly installed with xfce, Plank and Chromium.
 


Personally - this is something that I would never consider doing.
On my machines, I will manually add any users who I deem worthy of sudo privileges.
However, I believe it is possible to edit the sudoers file via a script.

Rather than trying to work it out, I did a quick bit of duckduckgo-fu which yielded this thread on stackoverflow:

Which has a few ideas listed in it.... Phew, that saved my ol' thinker a little bit of work! Ha ha!
 
Personally - this is something that I would never consider doing.
On my machines, I will manually add any users who I deem worthy of sudo privileges.

I understand the risks. I'm just trying to create a user in a shell script, install yay using that user, and then finally deleting that user. There's no wrong with that. Also I want that specific user to have some sudo privilleges, that's why.

Thanks a lot for suggesting that forum to me. Was really helpful :D
 

Members online


Latest posts

Top