ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to administer a small group of ubuntu desktops in my classroom. I can use ssh to perform administrative tasks one at a time on each machine, but I want to automate these tasks through a small number of scripts. I am having trouble with running root commands through a script.
On other distros, I think I would simply ssh into the root account, and run the script. But as an ubuntu user, I have only ever used sudo, and folks at ubuntuforums are understandably hesitant to recommend logging in as root. Instead I am seeing suggestions to disable the password requirement for each specific command I want to run, which does not seem like best practice.
Should I enable the root account, give it a password, and ssh to the root account to run the scripts? To be specific, the scripts will do things like install updates, install programs, add or delete users, configure the desktop, etc.
I might try that, but why the recommendation to work around needing a password? Isn't there a way to log in remotely as a trusted administrative user, through the use of keys, in a way that retains sudo/superuser privileges?
I might try that, but why the recommendation to work around needing a password? Isn't there a way to log in remotely as a trusted administrative user, through the use of keys, in a way that retains sudo/superuser privileges?
You can log in as a trusted administrative user through the use of keys. However, as soon as that trusted administrative user tries to execute something as root via the sudo command, the user will get a password prompt for the sudo command (unless that has been disabled, which isn't a good idea). So if you want to run this in a script, you'll want to set NOPASSWD in the sudoers file for that user and those commands.
Here's where it's helpful to set up a service account that doesn't belong to anyone in particular to do these functions, so then you can lock down your sudo rules to exactly which functions you want to automate.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.