sudo E option does not work? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Seems to me that if I write a shell script in $HOME/path/to/script/myscript, and export PATH=$PATH:$HOME/path/to/script/ then sudo -E myscript should run the script right?
From sudo man page:
‑E
The ‑E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the ‑E option is specified and the user does not have permission to preserve the environment.
But sudo -E script can't find the command. I know I can just add /absolute/path/to/script/ to the files that determine the PATH variable for sudo env, but that's not the approach I want to take.
To address the comments:
#H2CO3: I have seen sudo sudo floating around the net, and it bugs me tremendously, it's literally saying "Give me superuser permissions to run superuser". I don't know if it would solve the problem, but it seems like a fundamentally flawed approach. Then again I started using linux/bsd systems back in the mid 90's so I take issue with just the sudo command itself.
#rici: The script does have executable permissions, but that's definitely something to check whenever something doesn't run in *nix systems =)

/etc/sudoers by default has a setting to reset the environment. And also defines a default secure_path which is in effect when you run sudo -E [cmd].
You will need to edit the /etc/sudoers file and add 'env_keep' and mention the variables you want to preserve.
Default env_keep += "PATH"
but before this comment out the secure_path line. Then try your command via sudo -E.

Related

Include sudo password in linux executable file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 3 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
I have this code in a linux executable file to start atom from there:
#! /bin/bash
sudo atom
I wanted to include sudo password after that lines of code, so the program will run automatically.
I wouldn't suggest hardcoding a password into your script as it carries a security risk.
Strictly speaking you can by doing:
echo "yourpassword" | sudo -S <command>
The -S flag will read the password from stdin.
There is another better way for you to allow password-less sudo commands by modifying your sudoers file.
Why you not use sudoers?
Try running atom without password.
Edit /etc/sudoers via visudo:
visudo -f /etc/sudoers
Put new line and save:
youuser ALL=(ALL:ALL) NOPASSWD: atom
do not forget to replace youuser
You dont need this. You need to use visudo:
sudo visudo
Then add line like this:
username ALL=(root) NOPASSWD: /path/to/script.sh
And then run your script using sudo script.sh without password

Changing from tcsh to bash? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am having difficulty with some shell commands and think that it is due to a failure of my shell being set to BASH.
The following commands solve my problem:
bash --login
Or simply by typing
bash
Therefore it seems that I need to reconfigure my shell to bash which should be simple. My default $SHELL variable is /bin/bash
I think it is due to the following setting under my terminal preferences:
run a custom command instead of my shell
/bin/tcsh/
Why should my shell preferences be set to this, what is the advantage/use of tcsh over bash?
Also, how should I overcome this issue while still retaining use of any of the features which may rely upon this default terminal preference (/bin/tcsh)
Here is some of my system information:
Ubuntu 14.02
$SHELL
/bin/bash
$BASH_VERSION
undefined variable
I have previously used the following command to change from DASH to BASH:
sudo dpkg-reconfigure dash
I have also previously used the following command:
sudo apt-get install csh
I suspect that you have /bin/bash already set, but to help you change it if not:
The default shell for an user is set inside /etc/passwd (usually).
You could see which is set for you by doing:
grep "user" /etc/passwd
Where user is your username in the system. The last value (after the last ":") is the value of shell set for you to use. You could change it in two ways, either by editing the file, or easier, by executing "chsh" (which means: "change login shell"):
$ chsh
It will ask for your password and then will ask for the shell you want to use, just write "/bin/bash".
Done. To make the changes apply to all the programs, just log-out and log-in again.
A second level of configuration belongs to the window that contain the console. I suspect that you are using gnome-terminal (the usual for Ubuntu). If not, then it may be konsole (for a KDE desktop). In any one of those, check that the configuration is not set to call "tcsh". Say which console/terminal you are using to give tips if you need them.

sudoers allow command with one option - refuse with other option [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am looking for a solution to the following:
Allow in sudoers file the execution on a command with option A, but refuse the same command with option B:
Example:
Allow this:
sudo my_command optionA
Dissallow this:
sudo my_command optionB
Is this possible ?
You can easily specify which parameters are allowed.
For example, I have a user testuser. The file you must edit is /etc/sudoers, but remember to do it with visudo command - it verifies the content of the file, so you won't end up with a typo that would prevent you from sudo'ing again (sometimes it's the only way to access root account).
So, enter visudo.
Let's say, that I want to allow test to run /bin/yes --help. I don't have right to x it for any other user than root.
What you want to add is:
testuser ALL=(ALL) /bin/yes --help
It means that testuser can run /bin/yes --help from any host as any user. By default, sudo /bin/yes --help will ask for testuser's password. sudo /bin/yes will give access denied.
If you want to allow it without providing a password, replace the line with:
testuser ALL=(ALL) NOPASSWD: /bin/yes --help
Please note that you cannot explicitly deny a parameter. If the testuser is a member of default sudoers group, this method will not work.

Change dir after 'sudo -i', in one command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Is there a way to switch dir after doing sudo -i (in one command)?
We use lots of ssh connections on work, and it is a pain to manually set them up when you reboot your pc. So I'm trying to make aliases like ssh remote-dev -t 'sudo -i; bash -l', which connects me to a machine and makes me root there (it is required to do that way; because of Kerberos we can't directly ssh root#...)
So what I would like to do now is expanding the above command in a way that I can also tell it to switch to a specific dir after the sudo, or open a specific file, or tail a logfile or something... Is that possible?
-- edit: Of course you could tell it to do some command everytime someone logs in via ssh. But this is a bad option, because only I want to have these commands to be executed; When other people connect to this machine, they probably want different commands.
-- edit: Sorry I posted it here, did not realize it is offtopic in stackoverflow
Try
sudo -i bash -c "cd /path/to/dir; exec bash"

Automatically run a program on startup under Linux Ubuntu [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I'd need a program to be run every time I start up my Ubuntu Linux. So I'd need to add it to my startup programs list. Just one problem: I'd need to do it via the terminal.
sudo mv /filename /etc/init.d/
sudo chmod +x /etc/init.d/filename
sudo update-rc.d filename defaults
The script should now start on boot. Note that this method also works with both hard links and symbolic links (ln).
At this point in the boot process PATH isn't set yet, so it is critical that absolute paths are used throughout. But, as pointed out in the comments by Steve HHH, explicitly declaring the full file path (/etc/init.d/filename) for the update-rc.d command is not valid in most versions of Linux. Per the manpage for update-rc.d, the second parameter is a script located in /etc/init.d/*.
Also as pointed out in the comments (by Charles Brandt), /filename must be an init style script. A good template was also provided - System V init script template.
As pointed out in the comments (by Russell Yan), this works only on default mode of update-rc.d.
According to the manual of update-rc.d, it can run on two modes: "the machines using the legacy mode will have a file /etc/init.d/.legacy-bootordering", in which case you have to pass sequence and runlevel configuration through command line arguments.
The equivalent argument set for the above example is
sudo update-rc.d filename start 20 2 3 4 5 . stop 20 0 1 6 .

Resources