0

I have a script where I'm trying to change user (from root) on boot. In /etc/rc.d/rc.local, I've changed it to cd into the script dir and execute it. It all works except for when it tries to execute:

sudo -u newuser ./myscript.sh

I get an error message:

sorry, you must have a tty to run sudo

So I went and looked in my /etc/sudoers file, and it is already set to !requiretty, which should turn that off. I have also tried alternatives such as gksudo, but apparently RHEL 6.5 only supports basic sudo.

I know the script works because I can execute it myself from terminal, it's just when I try and execute it from a boot script.

ALOIVIA
  • 41
  • 1
  • 9
  • 1
    you shouldn't need to use sudo when you're already root, use `su`. Also, this is probably off topic on SO, should go to superuser. – mata Jun 03 '15 at 10:37
  • Yes, you're right, thanks. And I'll take it to superuser next time! – ALOIVIA Jun 03 '15 at 10:46

2 Answers2

1

Just changed:

sudo -u newuser ./myscript.sh

To:

/bin/su -c ./myscript.sh newuser

And it seems to work. I guess because sudo is normally there to elevate your privileges but since it starts as root I don't really need it and can use su instead. Will try this out in various places to make sure it works 100%.

ALOIVIA
  • 41
  • 1
  • 9
0
su -u newuser -c ./myscript.sh 
Draken
  • 3,134
  • 13
  • 34
  • 54
Shailesh
  • 59
  • 6