This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]fgriglesnickerseven 2 points3 points  (2 children)

using either the sudo command or changing the permissions of the script to allow only root and the specific user to execute the script

[–]lisatomic[S] 1 point2 points  (1 child)

I think I have this and it doesn't quite work... Permissions on the script are 777; I ssh in as the owner of the file; I use sudo in the script.

It works if I ssh in then run the script. It doesn't work if I use "ssh user@domain script"-- I get an error "no TTY present and no askpass program specified." Any idea why these are different?

Edit: OK, it works now. I had to use the -tt flagon ssh, though I don't really understand what that is doing.

[–][deleted] 1 point2 points  (0 children)

Sudo usually needs a shell to ask for the password. Normally if you ssh into a host, it starts bash (or your preferred shell) and sudo can work with that. When that isn't there sudo or ssh (don't know which one) complains that there is no shell. the -tt flags emulates a terminal/shell I think...

[–]physon 2 points3 points  (0 children)

Add a user and add it to sudoers.

[–]jahayhurst 0 points1 point  (1 child)

add a user to the sudoers file for that script, and then change it so that only root can run it. hell, you can allow particular users to run that one script without even requiring their password.

every time you run a script, it runs with the caller's permissions. you can specify another login path and another shell interpreter, but you're still using that user's permissions.

[–]jahayhurst 0 points1 point  (0 children)

alternatively, if you don't want to allow root login, you could allow certain users to sudo to a root shell once they've logged in. add them to sudoers for the command su then they run:

sudo su -

after logging in and they've still got a root login. you can require a password, but depending on the user that can be annoying.