Apache2, SSH, and similar don't seem to work (unless restarted) upon booting, and logging in graphically to device. To make it work, I have to type /etc/init.d/apache2 restart, and do the same for SSH. I am planning on having my device without a monitor or keyboard. I setup login automatically, made a shell script restarting the services, and put it in ~/.kde/Autostart.

The reason that didn't work is because I need root privileges to restart a service. I need to restart this without any sort of input or monitor. How can I either allow non-root users to restart apache2, or allow root without password for this executable?

I also tried editing the sudoers file and adding:

username ALL = NOPASSWD: /etc/init.d/apache2
username ALL = NOPASSWD: /etc/init.d/ssh
username ALL = /etc/init.d/apache2
username ALL = /etc/init.d/ssh

It still says permission denied upon trying

Debian 8 (Jessie)

  • Apache, etc. should all work without having to log in or manually restart them. They do on all my machines, and I suspect almost everyone else running Jessie (or anything else, for that matter). I suggest figuring out why it doesn't work for you... Things to look at include journalctl -b, /var/log/apache2/, etc. Please feel free to ask further questions if needed to figure it out. – derobert Nov 25 '15 at 19:07
  • I suspect you've got Network Manager set bring up the network only for your user account, rather than system-wide. – roaima Nov 25 '15 at 19:13
  • 1
    Please edit your question and add the following command and it's output: ls -l /etc/{init,rc*}.d/*ssh* – RobertL Nov 25 '15 at 19:16

You could do this using sudo with nopasswd for the command you are running. BUT to me it looks like you are trying to create a workaround for a deeper problem which you probably should address.

| improve this answer | |
  • Yes, I tried something similar. I edited question to add that in. Please avoid posting these kind of posts in answers, as it will fit more in comments, once you have sufficient rep. – TheBro21 Nov 25 '15 at 18:52

I finally found a way to make echo enter the password (as the only issue was that I wouldn't have a keyboard).

echo -e "password\n" | sudo -S command --flag argument

the -e enables backslash escape, and the sudo -S enables STD input (so the input from the echo, pipelined). According to the manual, -S inputs need to end with the \n escape character

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.