sudoers file NOPASSWD entries ignored? - unix

My sudoers file is seemingly ignored. I appended these two lines via vim (sudo visudo):
theonlygusti ALL=(ALL) NOPASSWD: /usr/sbin/networksetup -setsocksfirewallproxy
theonlygusti ALL=(ALL) NOPASSWD: /usr/sbin/networksetup -setsocksfirewallproxystate
but when I run either command I am prompted to type a password:
$ sudo -n networksetup -setsocksfirewallproxy "Wi-Fi" localhost 3000
sudo: a password is required

The sudoers file only looks for exactly the command you give it. You are trying to run it with extra parameters that are not defined in the sudoers file; That is why you are getting prompted for a password.
Try something like this:
theonlygusti ALL = NOPASSWD : /usr/sbin/networksetup -setsocksfirewallproxy *, /usr/sbin/networksetup -setsocksfirewallproxystate *

Related

chmod with wildcard inside symlink

I'm setting up Tomcat on Centos according to https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-centos-7 , but with a twist: I put Tomcat in /opt/apache-tomcat-8.5.6 and then set up a symbolic link:
sudo ln -s /opt/apache-tomcat-8.5.6 /opt/tomcat
Now I change the group ownership of /opt/tomcat to tomcat:
sudo chgrp -R tomcat /opt/tomcat/conf
Then I give the tomcat group write access to the configuration directory:
sudo chmod g+rwx /opt/tomcat/conf
But here is the problem: I try to give the tomcat group read access to all the configuration files:
sudo chmod g+r /opt/tomcat/conf/*
That gives me an error: chmod: cannot access ‘/opt/tomcat/conf/*’: No such file or directory
What? Does chmod not accept wildcards? Or does it not look inside symbolic links? What's going on?
Note that I got around it by doing this:
sudo chmod g+r -R /opt/tomcat/conf
Does that give me effectively the same thing? (I know that it additionally makes the directory readable by the group, but that seems inconsequential --- the group could already read the directory.) Why doesn't the wildcard version work?
Globs are expanded by the current shell. This happens before sudo and chown are ever invoked.
If the current shell doesn't have access to list the files, the glob will be treated as unmatched and just left alone. This makes chmod try to access a file literally named *, which fails.
root# echo /root/.*
/root/.bash_history /root/.bashrc ...
user$ sudo echo /root/.*
/root/.*
The same is true for command substitution, process substitution and other expansions, which are similarly unaffected by sudo:
root# echo $(whoami)
root
user$ sudo echo $(whoami)
user
The shell is also responsible for pipes and redirects, which are also set up before sudo ever runs:
root# echo 60 > /proc/sys/vm/swappiness
(command exits successfully)
user$ sudo echo 60 > /proc/sys/vm/swappiness
bash: /proc/sys/vm/swappiness: Permission denied
In Unix terms, sudo is wrapper for execve(2), and therefore can't help with anything that you can't do through an execve call. If you need shell functionality from the target user, you need to manually invoke that shell:
user$ sudo sh -c 'chmod g+r /opt/tomcat/conf/*'

Unix Error: Username is not in the sudoers file. This incident will be reported [duplicate]

This question already has answers here:
Linux: 'Username' is not in the sudoers file. This incident will be reported [closed]
(11 answers)
Closed 2 years ago.
I am trying to add a particular user in the group using command: sudo usermod -a -G groupname username.
but getting error as "Username is not in the sudoers file. This incident will be reported".
I dont have any idea about sudoers file. Can anybody please help me on this.
The config file /etc/sudoers lists the users who are allowed to run which commands as which user.
On Ubuntu, this file contains a line allowing all users of the sudo group to run commands as the root user.
To check which users are in the sudo group you can type getent group sudo. You can also check the groups of your current user by typing id.
To allow another user to run sudo, you can add them to the sudo group:
sudo adduser username sudo
Or, if your current user can't run sudo, you will need to boot into "Recovery mode" from Grub (hold shift while booting, if your grub menu doesn't show up automatically), or add single to the linux ... initrd ... quiet splash line, then:
mount -o rw,remount /
adduser username sudo
Run adduser for each user you want to be able to sudo. Then exit & resume.

Linux: Running a specific command as root

I need to run a command as "some_user" without being asked for the password, so I type:
$ sudo visudo
Adding this line does work:
some_user ALL=NOPASSWD: ALL
But adding this line (with only the specific command "whitelisted") does not work:
some_user ALL=NOPASSWD: /etc/init.d/"some_service start"
$ sudo /etc/init.d/"some_service start"
...will still ask for the password.
What am I doing wrong?
EDIT: Corrected (but this still asks for password)
some_user ALL=NOPASSWD: /etc/init.d/"some_service start"
$ sudo /etc/init.d/some_service start
The problem is with the quotes, both on the command line and in the sudoers file. The quotes make sudo and the shell think that there should be a file in /etc/init.d named "some_service start", rather than seeing start as an argument to /etc/init.d/some_service.

User cannot execute a command when I already specified it in /etc/sudoers

Hello I want to run the following command as a user called arago:
`echo 1SgOSWjT | passwd --stdin JohnDoe`
This is to change the password for the user John Doe. However I get the following message:
Only root can do that.
I modified the /etc/sudoers file as follows:
`User_Alias ADMINS = arago`
`Cmnd_Alias LOCATE = /usr/bin/passwd`
`ADMINS ALL = NOPASSWD: LOCATE `
Why can I not still run the passwd command?
You probably need
echo 1SgOSWjT | sudo passwd --stdin JohnDoe
but it is a very bad habit that you are taking.
BTW, you might install the super package or the ninja package and use it instead of sudo
I believe however that your entire approach is a security risk.

testlink installation failed: checking if /var/testlink/logs/ directory exists

Today, I installed testlink. And after I select 'new Installation' and choose 'I agree' option, it failed at the second step. The failed message are as following:
Read/write permissions
For security reason we suggest that directories tagged with [S] on following messages, will be made UNREACHEABLE from browser
Checking if C:\xampp\htdocs\testlink\gui\templates_c directory exists OK
Checking if C:\xampp\htdocs\testlink\gui\templates_c directory is writable (by user used to run webserver process) OK
Checking if /var/testlink/logs/ directory exists [S] Failed!
Checking if /var/testlink/upload_area/ directory exists [S] Failed!
So, can anyone give me a hand? Many thanks!
In C:\xampp\htdocs\testlink\config.inc.php file, change
$g_repositoryPath = 'C:\xampp\htdocs\testlink\upload_area';
$tlCfg->log_path = 'C:\xampp\htdocs\testlink\logs';
Worked for me , make sure you dont have the slash at the end.
i.e, make sure that it is NOT:
$g_repositoryPath = 'C:\xampp\htdocs\testlink\upload_area\';
$tlCfg->log_path = 'C:\xampp\htdocs\testlink\logs\';
If you installed the XAMPP or testlink in another directories, change the paths above accordingly.
Go to config.inc.php and log directory ($tlCfg->log_path) edit the path to C:\xampp\testlink\logs and upload directory ($g_repositoryPath) to C:\xampp\testlink\upload_area
In some cases, you would do like this:
Go to C:\xampp\htdocs\testlink\config.inc.php1
and log directory ($tlCfg->log_path) edit the path to C:\xampp\htdocs\testlink\logs
and upload directory ($g_repositoryPath) to C:\xampp\htdocs\testlink\upload_area
Then you have:
$g_repositoryPath = 'C:\xampp\htdocs\testlink\upload_area';
$tlCfg->log_path = 'C:\xampp\htdocs\testlink\logs';
I had paths set correct , also user, group and access are set correct and still can not get rid of issue. It took me very long to go to the root cause, the issue lies at- http daemon does not have access to file in concern due to SELinux policies. So simple chown, chmod would not help(group and user access). For testlink 1.16 I resolved it with re-installing with sudo user, but for upgrade, an issue arose again even with sudo user.
And resolved issue by executing following commands, I hope this helps. (Note: You might have to mend attributes to run it successfully)
$chcon -t httpd_sys_content_rw_t "<path_to_testlink_folder>/gui/templates_c/"
$chcon -t httpd_sys_content_rw_t "/<path_to_testlink_folder>/upload_area/"
$chcon -t httpd_sys_content_rw_t "<path_to_testlink_folder>/logs"
$semanage fcontext -a -t httpd_sys_content_rw_t "<path_to_testlink_folder>(/.*)?"
$restorecon -R -v path_to_testlink_folder
Ubuntu 12.04 - All you have to do is chmod 777 these directories, Fails will become Pass.
~$ cd into /var/www/testlink
~$ sudo chmod 777 ./gui/templates_c/
~$ sudo chmod 777 ./upload_area/
~$ sudo chmod 777 ./logs/
Whatever the instructions say is total BS. Making these directories unreachable from browser is optional, and that created a confusion. if you chmod 777 them, your Fails will turn into pass and now you'll be able to proceed to step 3 of your testlink installation. Tested with testlink version 1.9.5.
For Mac OS Users try this in 1.9.19 version:
Make Sure with your folder name.
In config.inc.php file:
$tlCfg->log_path = TL_ABS_PATH . 'logs' . DIRECTORY_SEPARATOR;
$g_repositoryPath= TL_ABS_PATH . 'upload_area' . DIRECTORY_SEPARATOR;
After this if you got read write permission issue failed.
Goto testlink -> logs / upload_area -> press Command + I -> in Permission Enable Read Write to Everyone.
on Linux; ensure the paths are as follows:
$tlCfg->log_path
$g_repositoryPath
are
/var/www/html/testlink/logs/
/var/www/html/testlink/upload_area/
Valid for ubuntu 16.04 LTS add permisions
Change:
$g_repositoryPath = 'var/www/html/testlink/upload_area'; //linux user
$tlCfg->log_path = 'var/www/html/testlink/logs';
~$ cd into /var/www/testlink
~$ sudo chmod 777 ./gui/templates_c/
~$ sudo chmod 777 ./upload_area/
~$ sudo chmod 777 ./logs/
In CentOS go to /var/www/html/testlink-code-1.9.16 and edit the file custom_config.inc.php replace these two lines
// $tlCfg->log_path = '/var/testlink-ga-testlink-code/logs/'; /* unix example */
// $g_repositoryPath = '/var/testlink-ga-testlink-code/upload_area/'; /* unix example */
with
$tlCfg->log_path = '/var/www/html/testlink-code-1.9.16/logs/';
$g_repositoryPath = '/var/www/html/testlink-code-1.9.16/upload_area/';
Make sure you have disabled the selinux. If not to do so edit the file /etc/sysconfig/selinux and change the variable SELINUX to disabled and reboot the machine. Now these errors should have gone.
on ubuntu 18.04, will need to run
apt-get remove apparmor
in order to install it
To solve the problem :
Checking if /var/www/html/testlink-1.9.16/gui/templates_c directory is writable (by user used to run webserver process) on Centos 7.
Disable SELinux, and then restart your system.
You should no longer have this error message.

Resources