Reputation: 692
I'm thinking about writing a Rails application to manage servers like cPanel.
The hardest part is to select the best way to run commands that require root privileges, like adduser
, or doing things that require another user's privileges, like changing nginx config files.
I know only two ways to achieve this:
Which of these ways are best? Does there exist another way to to this?
Upvotes: 6
Views: 2482
Reputation: 47561
sudo -i
I tried doing things like sudo bundle exec rails console
but it wouldn't quite run it as root so when I tried to create a directory from the console it let me know that I did not have the correct permissions.
However, using sudo -i
it enters you into an "interactive console" as the sudo root user and then you can run bundle exec rails console
as the sudo root user.
Hopes that helps others.
Upvotes: 4
Reputation: 160581
You need to do #2.
Start your application as root, and you will be able to do all operations as root.
Writing code to run as a daemon would work also, but it's harder to debug.
In either case you have to protect against hacking attempts via unauthorized access. One slip and your system would be compromised.
Upvotes: 3