Skip to content

Instantly share code, notes, and snippets.

@tanaka-geek
Last active April 24, 2021 15:29
Show Gist options
  • Save tanaka-geek/747be64cf2e6366f184ae7eddcd9d6bd to your computer and use it in GitHub Desktop.
Save tanaka-geek/747be64cf2e6366f184ae7eddcd9d6bd to your computer and use it in GitHub Desktop.
sudo -l shows what you can execute as sudo

If no command is specified, the -l (list) option will list the allowed (and forbidden) commands for the invoking user (or the user specified by the -U option) on the current host

sudo -l 
Matching Defaults entries for fredf on dc-9:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

sudo --list reads configuration file and shows the matching user's allowed commands

root@dc-9:~# cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults	env_reset
Defaults	mail_badpass
Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root	ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo	ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

fredf	ALL=(root) NOPASSWD: /opt/devstuff/dist/test/test

When executing the file with executable permission must be specified as absolute path as so in /etc/sudoers

sudo /opt/devstuff/dist/test/test # this works
cd opt/devstuff/dist/test && sudo ./test # does not work because it is relative path

absolute path and relative path are important!

rooting a cronjob

echo 'echo "fluffy ALL=(root) NOPASSWD: ALL" > /etc/sudoers' >> that.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment