Skip to main content
Share Your Experience: Take the 2024 Developer Survey
16 votes
Accepted

Why should I use `sudo` with the `passwd` command to change the password of another user?

In this particular implementation the passwd command needs to run as the root user to be able to change anyone's password. The passwd application has a piece of code that checks whether you are the ...
Chris Davies's user avatar
16 votes
Accepted

sudo persistent across ssh logins

This is a configuration setting in the sudoers file. It's unusual because it's not the default, but not necessarily unsafe. See man sudoers: sudoers uses per-user time stamp files for credential ...
Chris Davies's user avatar
14 votes

linux sudo list permitted commands

Use sudo -l to get your access rights. The output might look like this: #> sudo -l Matching Defaults entries for myuser on myhost: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/...
oldium's user avatar
  • 143
13 votes
Accepted

linux sudo list permitted commands

Run sudo -l. Depending on how sudo is configured on your system, it might request your password first, but it will display all sudo configuration options that apply to your account, and then all the ...
telcoM's user avatar
  • 98k
11 votes
Accepted

Can I install programs in linux from any directory?

Yes, absolutely. The location you run a command from has no effect on anything except in the specific case where you use a tool that requires files in its current directory. That isn't the case for ...
terdon's user avatar
  • 243k
11 votes
Accepted

Why does `less` show "This account is not available" when run on a file from a root login shell?

This happens because of less’s method of invoking commands specified in LESSOPEN or LESSCLOSE. If the SHELL environment variable is set, it uses its value as the shell to use to run them. Thus in your ...
Stephen Kitt's user avatar
8 votes

Detecting sudo use without logs

You can play around with the environ file under /proc/$pid. This contains the environment of the process with PID $pid and for commands launched with sudo, that file should contain the SUDO_USER ...
terdon's user avatar
  • 243k
7 votes

Why should I use `sudo` with the `passwd` command to change the password of another user?

Being able to change another user's password is a massive security breach, hence why passwd does not allow it unless you are already root.
Jörg W Mittag's user avatar
6 votes

Sudo -i giving error

sudo -i user2 does not switch to user2 at all. It literally means "run command user2 as root, in an environment that matches root's login environment." To switch to user2, the command needs ...
telcoM's user avatar
  • 98k
5 votes
Accepted

How to install sudo on Alpine 3.17 VM?

In /etc/apk/repositories the community repo is commented out. The sudo and a lot of other packages are in that repo. sed -i 's/#\(.*\/community\)/\1/' /etc/apk/repositories
stoggy's user avatar
  • 236
5 votes
Accepted

/proc/self/fd/2 can not be accessed under `sudo -u other_user`

sudo -u A_USER bash -c 'cmd | tee /dev/fd/2' Or: sudo -u A_USER sh -c 'cmd | tee /dev/fd/2' as there's nothing bash-specific in there, would work on systems other than Linux or Cygwin. While on most ...
Stéphane Chazelas's user avatar
5 votes

how to configure sudo to allow certain parameter

Sudo does have the ability to allow selectively multi-word command lines, but it's a bad idea, all around. However, to the best of my knowledge, variable placeholders are not among the things sudoers ...
Marcus Müller's user avatar
4 votes

Broken Debian 10 stable server by installing 3 or 4 small testing packages... Can't SSH anymore

Debian 10 has libc6 version 2.28-10+deb10u2, but the packages of current testing depend on libc6 version 2.34 or greater. So it looks like your attempt must have triggered a libc version update, which ...
telcoM's user avatar
  • 98k
4 votes

Can I install programs in linux from any directory?

If you use a package manager, then yes, the directory you're installing your program from doesn't matter. That package that is going to be installed knows where every file belongs, and unless you ...
Guntram Blohm's user avatar
4 votes
Accepted

Executing a shell script with sudo / no password

First off, make sure you always use visudo to edit /etc/sudoers. It will perform syntax checks for you so that it's less likely you end up shutting yourself out. Now, use that command to remove the ...
Chris Davies's user avatar
4 votes
Accepted

sudoers NOPASSWD tag doesn't seem to work

Please run sudo -l and see if you have other allowed sudo command lines defined for your user. This will display all applicable sudoers configuration lines, both from the main configuration and from ...
telcoM's user avatar
  • 98k
3 votes
Accepted

Letting a stranger in safely

Remove that sudoers line! You don't need to say that someone can't have access as that's the default. Furthermore you're opening up a major security hole with a trivial attack surface. These commands ...
Chris Davies's user avatar
3 votes

Letting a stranger in safely

You don't have to do anything. By default a user does not have sudo access, and to use su the user needs the root password. As long as you don't explicitly allow a user to use sudo, either by adding ...
Gerald Schneider's user avatar
3 votes
Accepted

`sudo --preserve-env=MY_VAR` vs `sudo env MY_VAR=$MY_VAR`

Interesting question. First of all setting the environment manually is tedious so --preserve-env is obviously better. For the security aspect: the sudo configuration can disallow you to execute env ...
Paul Pazderski's user avatar
3 votes
Accepted

Is it possible to grant a specific privilege to a user without sudo?

I can think of two ways of doing this. For both you'll need to write and compile a program that does the work you want (eg calling stime(2)). You can't just call date directly. And you'll need a ...
Stephen Harris's user avatar
3 votes

sudo rm -rf /* is not working

You're trying to remove all files and directories from the system. This includes /proc and /sys, which are virtual filesystems provided by the kernel and contain files that cannot be deleted. As an ...
Chris Davies's user avatar
3 votes
Accepted

What does it mean to copy a command to a different name?

Commands are usually(*) files, and files can be copied under different names. e.g. $ cp /bin/ls /tmp/lslsls $ % /tmp/lslsls -l /tmp/lslsls -rwxr-xr-x 1 ilkkachu wheel 187040 Dec 5 20:03 /tmp/...
ilkkachu's user avatar
  • 140k
3 votes

Issue with make and sudo make in Linux kernel module compilation

Your sudo is configured to clean up the environment before running the command it’s given; PWD is cleared before make runs. To change this, you can ask sudo not to clean up the environment: sudo -E ...
Stephen Kitt's user avatar
3 votes
Accepted

Crontab doesn't open for user

The crontab command has lost its permissions. For example, on my (Raspbian) system the permissions include setgid crontab (the s permission bit for the group): -rwxr-sr-x 1 root crontab 30452 Feb 22 ...
Chris Davies's user avatar
3 votes
Accepted

How to programmatically determine whether superuser elevation is necessary to invoke code?

Consequently, I ask whether anyone knows of any methods of programmatically determining whether a command necessitates user elevation to invoke it. I am aware that switching users when invoking ...
Marcus Müller's user avatar
3 votes

Trouble with setting up sudoers file in Debian 12

Ensure id shows you are in the "sudo" group (logout/login if needed). Also, ensure that there is a directive like %sudo ALL=(ALL:ALL) ALL in the sudoer config. Also, sometimes distros (or ...
GammaZoid's user avatar
  • 114
2 votes
Accepted

How should I use `systemctl --global`?

--global: When used with enable and disable, operate on the global user configuration directory, thus enabling or disabling a unit file globally for all future logins of all users. The systemctl --...
Joel Purra's user avatar
2 votes
Accepted

Run one command as root within script

sudo allows for entries in /etc/sudoers to have a NOPASSWD: option. And it also allows for ALL to be the source user. So an entry such as ALL ALL=(root) NOPASSWD: /bin/id Would allow anyone to run ...
Stephen Harris's user avatar
2 votes

Reducing repetition in sudoers file

You can use POSIX extended regular expressions in sudo version 1.9.10 onwards. The expression is delimited by ^ and $. (It cannot match command and arguments combined in a single regex). For example, (...
meuh's user avatar
  • 51.7k
2 votes

Can you make Sudo display a message when access is granted?

I ended up creating a Bash script named sudo: set -e console="$(tty)" readonly console /path/to/real/sudo -v # Sudo normally writes directly to the terminal device instead of # writing to ...
Ginger Jesus's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible