Questions tagged [sudo]

The sudo command is a program for Unix and Unix-like computer operating systems that allows a user to run programs with the security privileges of another user (normally the superuser, or root). The name is an abbreviation for "substitute user do" (as in, do a command as if started by another user).

The sudo command is a program for Unix and Unix-like computer operating systems that allows a user to run programs with the security privileges of another user (normally the superuser, or root). The name is an abbreviation for "substitute user do" (as in, do a command as if started by another user).

Unlike the su command, users typically supply their own password to sudo rather than the root password. After authentication, and if the /etc/sudoers configuration file permits the user access, then the system will invoke the requested command.

2818 questions
1706
votes
9 answers

How does the vim "write with sudo" trick work?

Many of you have probably seen the command that allows you to write on a file that needs root permission, even when you forgot to open vim with sudo: :w !sudo tee % The thing is that I don't get what is exactly happening here. I have already…
Doppelganger
  • 20,114
  • 8
  • 31
  • 29
1485
votes
39 answers

How to fix npm throwing error without sudo

I just installed node and npm through the package on nodejs.org, and whenever I try to search or install something with npm, it throws the following error unless I sudo the command. I have a feeling this is a permissions issue? I am already the…
Chad
  • 18,076
  • 8
  • 31
  • 41
1103
votes
15 answers

How do I use sudo to redirect output to a location I don't have permission to write to?

I've been given sudo access on one of our development RedHat linux boxes, and I seem to find myself quite often needing to redirect output to a location I don't normally have write access to. The trouble is, this contrived example doesn't work: sudo…
Jonathan
  • 25,873
  • 13
  • 66
  • 85
709
votes
15 answers

sudo echo "something" >> /etc/privilegedFile doesn't work

This is a pretty simple question, at least it seems like it should be, about sudo permissions in Linux. There are a lot of times when I just want to append something to /etc/hosts or a similar file but end up not being able to because both > and >>…
David
  • 17,673
  • 10
  • 68
  • 97
574
votes
7 answers

How to keep environment variables when using sudo

When I use any command with sudo the environment variables are not there. For example after setting HTTP_PROXY the command wget works fine without sudo. However if I type sudo wget it says it can't bypass the proxy setting.
Ahmed Aswani
  • 8,271
  • 7
  • 33
  • 54
525
votes
30 answers

How to fix 'sudo: no tty present and no askpass program specified' error?

I am trying to compile some sources using a makefile. In the makefile there is a bunch of commands that need to be ran as sudo. When I compile the sources from a terminal all goes fine and the make is paused the first time a sudo command is ran…
feeling_lonely
  • 6,665
  • 4
  • 27
  • 53
486
votes
14 answers

How to use sudo inside a docker container?

Normally, docker containers are run using the user root. I'd like to use a different user, which is no problem using docker's USER directive. But this user should be able to use sudo inside the container. This command is missing. Here's a simple…
drubb
  • 14,533
  • 7
  • 15
  • 11
295
votes
18 answers

Why does sudo change the PATH?

This is the PATH variable without sudo: $ echo 'echo $PATH' | sh /opt/local/ruby/bin:/usr/bin:/bin This is the PATH variable with sudo: $ echo 'echo $PATH' | sudo sh /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin As…
Michiel de Mare
  • 41,982
  • 29
  • 103
  • 134
280
votes
2 answers

How to apt-get install in a GitHub Actions workflow?

In the new GitHub Actions, I am trying to install a package in order to use it in one of the next steps. name: CI on: [push, pull_request] jobs: translations: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 with: …
Niklas
  • 3,753
  • 4
  • 21
  • 29
217
votes
11 answers

Command not found when using sudo

I have a script called foo.sh in my home folder. When I navigate to this folder, and enter ./foo.sh, I get -bash: ./foo.sh: Permission denied. When I use sudo ./foo.sh, I get sudo: foo.sh: command not found. Why does this happen and how I can…
Neko
  • 3,550
  • 7
  • 28
  • 34
202
votes
8 answers

What is the proper way to sudo over ssh?

I have a script which runs another script via SSH on a remote server using sudo. However, when I type the password, it shows up on the terminal. (Otherwise it works fine) ssh user@server "sudo script" What's the proper way to do this so I can type…
darkfeline
  • 9,404
  • 5
  • 31
  • 32
188
votes
10 answers

Open a file with su/sudo inside Emacs

Suppose I want to open a file in an existing Emacs session using su or sudo, without dropping down to a shell and doing sudoedit or sudo emacs. One way to do this is C-x C-f /sudo::/path/to/file but this requires an expensive round-trip through…
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
180
votes
11 answers

How to run two commands with sudo?

Is there any way how I can run two Db2 commands from a command line? They will be called from a PHP exec command. db2 connect to ttt (note that we need to have the connection live for the second command db2 UPDATE CONTACT SET EMAIL_ADDRESS =…
Radek
  • 13,813
  • 52
  • 161
  • 255
180
votes
9 answers

How do I use su to execute the rest of the bash script as that user?

I've written a script that takes, as an argument, a string that is a concatenation of a username and a project. The script is supposed to switch (su) to the username, cd to a specific directory based upon the project string. I basically want to…
Son of the Wai-Pan
  • 12,371
  • 16
  • 46
  • 55
180
votes
47 answers

npm install errors with Error: ENOENT, chmod

I am trying to globally install an npm module I just published. Every time I try to install, either from npm or the folder, I get this error. npm ERR! Error: ENOENT, chmod '/usr/local/lib/node_modules/takeapeek/lib/cmd.js' npm ERR! If you need help,…
giodamelio
  • 5,465
  • 14
  • 44
  • 72
1
2 3
99 100