Append path to sudo secure_path - path

I am trying to append a path like say /usr/local/ssh in /etc/sudoers.d/path to /etc/sudoers which already has:
Defaults secure_path="/usr/bin:/sbin"
How can I append another path to secure_path in /etc/sudoers.d/path without changing the default sudoers. If I put in the new file this, then it overrides the default secure_path in sudoers.:
Defaults secure_path="/usr/bin:/sbin"

Related

Adding path variable in wsl

I have added a path in bashrc, still, the command is not found. When tried in ubuntu it worked but not in WSL. Why this happen?.
export PATH=\wsl$\Ubuntu\usr\local\mbdyn\bin:$PATH
added same path in .bashrc
error: command not found
**Please see the attached image
As you have been told, the forward slash to use is / and if you use the command
PATH="$PATH:/folder/subfolder/"
that value will only last in the PATH for the duration of the session.
To include a value in the PATH permanently, edit the .bashrc file from your home
$ sudo vim ~/.bashrc
you add at the end
export PATH="$PATH:/folder/subfolder/"
you save and you will have that value in the PATH in each session
You will need to modify the PATH variable as follows:
PATH="$PATH:/usr/local/mbdyn/bin"

how do I change default editor for sudo vipw from "vi" to "vim" by tcsh in FreeBSD

When I use command sudo vipw to edit my password file, It's always use vi as editor. I don't like this very much and want to change it to vim.
I already tried:
Add export EDITOR=/usr/local/bin/vim in /etc/profile.
But shell told me "export: Command not found". I thought the reason is export is built-in function only in bash. And I don't want to change my shell.
AddEDITOR=/usr/lcoal/bin/vim in default block of /etc/login.conf
Add setenv EDITOR vim in /root/.cshrc, /.cshrc, ~/.cshrc
All above didn't work at all.
I have google for hours but could not find anything help.
Your /etc/sudoers file doesn't keep your EDITOR environment variable.
I personally have an /etc/sudoers.d/local file, something like
# We don't need to worry about wheel users breaking in to get root access because they already have it.
Defaults:%wheel env_keep+="HOME EDITOR",!set_home,shell_noargs
I'm not sure why this isn't the default, since wheel users have already been given full access. But it's apparently prevailing wisdom to continue hassling them.
Note: If you're using an older /etc/sudoers file that doesn't support an /etc/sudoers.d directory, these lines can be dropped in there... or you could add #includedir /etc/sudoers.d as the last line of your /etc/sudoers file to enable an /etc/sudoers.d directory. Um, yes, the # is a required part of that line, because someone thought it was important for that directive to look like a comment.
Try adding this to the root user /root/.chsrc:
setenv EDITOR vim
or to set it globally to all users using shell tcsh/csh add it in /etc/csh.cshrc
From the man:
A login shell begins by executing commands from the system files /etc/csh.cshrc
and /etc/csh.login. It then executes commands from files in the user's home directory:
first ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrc ...
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup.
Also verify vim is installed since is not by default, you could try:
pkg install vim-console
setting the EDITOR or VISUAL environment variable is the key.
if you don't want to go to the trouble of modifying config files (which is indeed the long term solution) then you could sudo su - to get to the root prompt and then you could export EDITOR=/usr/bin/vim before running vipw
There is an empty file called .selected_editor in $HOME (/root).
Remove it and the next call to vipw will ask you to select the editor.

cygwin + $PATH + adding path to configuration

which one of these files do I have to edit so that I can launch Notepad++ from my cygwin Terminal?
$ find -name ".*"
.
./.bashrc
./.bash_history
./.bash_profile
./.inputrc
./.profile
This is the command I give in the terminal to add the Notepad++ to the directory
$ export PATH=$PATH:/cygdrive/c/Program\ Files\ \(x86\)/Notepad++/
So if i do a echo $PATH I can see that the directory was added to my PATH
This then allows me to open files in Notepad++ for editing
$ notepad++.exe filename
But i want my cygwin to be like this everytime I launch it. How can this be done?
NOTE: Using cygwing on windows7
There are also another ways to do what you want. You don't have to add Notepad's directory to the PATH, when you need only one executable from that directory. The main advantage of a directory in the PATH is that every executable in that directory is available anywhere.
You can use for example alias, symbolic link or function. Each method creates the "npp" command, which you can then use as you suggested: npp filename. Advantage over the PATH method is that you can name it whatever you want.
alias
alias npp='/cygdrive/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe'
You can put it for example to your .bashrc. You can also add a parameters to an alias command. The name of an alias can be whatever you want.
symbolic link
ln -s /cygdrive/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe /usr/local/bin/npp
This will create a file in the directory /usr/local/bin which is already in your PATH. This file is symbolic link (something like Windows' shortcut) to the Notepad++ executable. The name of a symbolic link (the last part of the command) can be whatever you want, but you can't use a parameters there.
General format of the ln command for symbolic link:
ln -s target link_name
function
npp () {
/cygdrive/c/Program\ Files/Notepad++/notepad++.exe $(cygpath -w -- "$#")
}
Again, you can put it for example to your .bashrc and name it whatever you want. cygpath converts path to the file from Linux to the Windows format, but it should not be necessary.
By editing ./bashrc file, you can achieve your goal. Here is the link for Cygwin Tutorial: Use External Editor Notepad.

How can I change the path for root permanently in solaris sparc?

I have edited /etc/profile but the path only gets changed for normal users whereas the change does not reflect for root, how can I make it such that the path also gets changed for root?
On Solaris, regular users and root default PATH are defined in /etc/default/login and /etc/default/su in the PATH & SUPATH variables.
root uses a different shell from everybody else; or very definitely should: /bin/sh
If you used bash/ksh syntax:
export PATH=${PATH}:/new/path1:/new/path2
...will not work.
PATH=${PATH}:/new/path1:/new/path2
export PATH
This fits /bin/sh syntax

How to permanently change sudo's $PATH variable (Ubuntu 9.x)

I want add some directory to the $PATH when running sudo, this is a (semi) permanent requirement, not something that needs to be added to the scripts themselves. I notice that Django has managed to do it, (my $PATH when running sudo is "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/django/django-trunk/django/bin") - so how did it do that?
This is the line in the sudoers file that resets:
Defaults env_reset
You can work around this by adding PATH to env_keeps or by adding this line:
Defaults env_keep = "PATH"
EDIT: meder, you do not disable env_reset, you simply bypass the path reset
Or you can remove the offending env_reset line.
Even better though, you can declare a secure_path that will replace PATH when sudo is run:
Defaults secure_path="/bin:/usr/bin"
That way you can control what specific directories to include in the path.
I think this should work out if you save it in /root/.bashrc:
export PATH=/www/foo:$PATH
I forget if it's PATH or PYTHONPATH and if it actually matters, this is based on my user's .bashrc:
export PYTHONPATH=/www/django:$PYTHONPATH
You can set the variable in /etc/environment, and then use "sudo -i" to run the script (works in ubuntu 10.10).

Resources