DEV Community

Stack All Flow
Stack All Flow

Posted on • Originally published at stackallflow.com on

How to Solve “Permission Denied” When Using Sudo With Redirection in Bash?

bashcommand linesudo

When using sudo to allow edits to files, I regularly get ‘permission denied’.

For example, my mouse is jittery and sluggish, so I want to disable polling:

sudo echo "options drm_kms_helper poll=N">/etc/modprobe.d/local.conf

Enter fullscreen mode Exit fullscreen mode

I’m prompted for a password, and then get:

bash: /etc/modprobe.d/local.conf: Permission denied

Enter fullscreen mode Exit fullscreen mode

So I tried to do a temporary change to disable polling by using:

sudo echo N> /sys/module/drm_kms_helper/parameters/poll

Enter fullscreen mode Exit fullscreen mode

Yet again the system responded with:

bash: /sys/module/drm_kms_helper/parameters/poll: Permission denied

Enter fullscreen mode Exit fullscreen mode

Any ideas?

Accepted Answer

Output redirection (via the > operator) is done by the shell, not by echo. You have to login as root

sudo -i

Enter fullscreen mode Exit fullscreen mode

Then you can use redirection

echo N> /sys/module/drm_kms_helper/parameters/poll

Enter fullscreen mode Exit fullscreen mode

Otherwise you can run bash string with sudo

sudo bash -c "echo N> /sys/module/drm_kms_helper/parameters/poll"

Enter fullscreen mode Exit fullscreen mode

The post How to Solve “Permission Denied” When Using Sudo With Redirection in Bash? appeared first on Stack All Flow.

Discussion (0)