Skip to main content
Minor grammatical fiddling
Source Link
Chris Davies
  • 128.5k
  • 16
  • 179
  • 325

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 inappropriate first comma (between ALL and NOPASSWD):

(ALL) ALL NOPASSWD: /sbin/systemctl suspend 

Next, know that your modeset command is too complex to define directly and reliably in the sudoers file. Consider this command (with or without sudo):

sh -c 'date >/tmp/date' 

The quotes will be parsed by your own (interactive) shell and the quoted string passed as a single word to. The sh. The will see two arguments, -c and date >/tmp/date; the quotes are never seen by the command. Similarly, the quotes here will never be seen by sudo either:

sudo sh -c 'date >/tmp/date' 

The sudo will see three arguments sh, -c, and date >/tmp/date.

Therefore my suggestion would be that you create a short shell script that performs the required action, and add that to your sudoers file. (Run the following block of commands as root - use sudo -s to get a root shell.)

cat >/usr/local/bin/modeset1 <<EOF #!/bin/sh echo ON > /proc/acpi/bbswitch modprobe nvidia modprobe nvidia_drm modeset=1 EOF chown root /usr/local/bin/modeset1 chmod a=rx,u+w /usr/local/bin/modeset1 

Now add this line to sudoers using the visudo command:

(ALL) ALL NOPASSWD: /usr/local/bin/modeset1 

Once /usr/local/bin has been added to your $PATH you just invoke it with your usual user account as a standard command,

sudo modeset1 

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 inappropriate first comma (between ALL and NOPASSWD):

(ALL) ALL NOPASSWD: /sbin/systemctl suspend 

Next, know that your modeset command is too complex to define directly and reliably in the sudoers file. Consider this command (with or without sudo):

sh -c 'date >/tmp/date' 

The quotes will be parsed by your own (interactive) shell and the quoted string passed as a single word to sh. The quotes are never seen by the command. Similarly, the quotes will never be seen by sudo either:

sudo sh -c 'date >/tmp/date' 

Therefore my suggestion would be that you create a short shell script that performs the required action, and add that to your sudoers file. (Run the following block of commands as root - use sudo -s to get a root shell.)

cat >/usr/local/bin/modeset1 <<EOF #!/bin/sh echo ON > /proc/acpi/bbswitch modprobe nvidia modprobe nvidia_drm modeset=1 EOF chown root /usr/local/bin/modeset1 chmod a=rx,u+w /usr/local/bin/modeset1 

Now add this line to sudoers using the visudo command:

(ALL) ALL NOPASSWD: /usr/local/bin/modeset1 

Once /usr/local/bin has been added to your $PATH you just invoke it with your usual user account as a standard command,

sudo modeset1 

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 inappropriate first comma (between ALL and NOPASSWD):

(ALL) ALL NOPASSWD: /sbin/systemctl suspend 

Next, know that your modeset command is too complex to define directly and reliably in the sudoers file. Consider this command (with or without sudo):

sh -c 'date >/tmp/date' 

The quotes will be parsed by your own (interactive) shell and the quoted string passed as a single word. The sh will see two arguments, -c and date >/tmp/date; the quotes are never seen by the command. Similarly, the quotes here will never be seen by sudo either:

sudo sh -c 'date >/tmp/date' 

The sudo will see three arguments sh, -c, and date >/tmp/date.

Therefore my suggestion would be that you create a short shell script that performs the required action, and add that to your sudoers file. (Run the following block of commands as root - use sudo -s to get a root shell.)

cat >/usr/local/bin/modeset1 <<EOF #!/bin/sh echo ON > /proc/acpi/bbswitch modprobe nvidia modprobe nvidia_drm modeset=1 EOF chown root /usr/local/bin/modeset1 chmod a=rx,u+w /usr/local/bin/modeset1 

Now add this line to sudoers using the visudo command:

(ALL) ALL NOPASSWD: /usr/local/bin/modeset1 

Once /usr/local/bin has been added to your $PATH you just invoke it with your usual user account as a standard command,

sudo modeset1 
Source Link
Chris Davies
  • 128.5k
  • 16
  • 179
  • 325

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 inappropriate first comma (between ALL and NOPASSWD):

(ALL) ALL NOPASSWD: /sbin/systemctl suspend 

Next, know that your modeset command is too complex to define directly and reliably in the sudoers file. Consider this command (with or without sudo):

sh -c 'date >/tmp/date' 

The quotes will be parsed by your own (interactive) shell and the quoted string passed as a single word to sh. The quotes are never seen by the command. Similarly, the quotes will never be seen by sudo either:

sudo sh -c 'date >/tmp/date' 

Therefore my suggestion would be that you create a short shell script that performs the required action, and add that to your sudoers file. (Run the following block of commands as root - use sudo -s to get a root shell.)

cat >/usr/local/bin/modeset1 <<EOF #!/bin/sh echo ON > /proc/acpi/bbswitch modprobe nvidia modprobe nvidia_drm modeset=1 EOF chown root /usr/local/bin/modeset1 chmod a=rx,u+w /usr/local/bin/modeset1 

Now add this line to sudoers using the visudo command:

(ALL) ALL NOPASSWD: /usr/local/bin/modeset1 

Once /usr/local/bin has been added to your $PATH you just invoke it with your usual user account as a standard command,

sudo modeset1