sudo is a tool which allows users to run commands as another user (usually the root user)

learn more… | top users | synonyms

53
votes
8answers
19k views

sudo su - username while keeping ssh key forwarding

If I have a server A into which I can login with my ssh key and I have the ability to "sudo su - otheruser", I lose key forwarding, because the env variables are removed and the socket is only ...
39
votes
6answers
3k views

Is it OK to set up passwordless `sudo` on a cloud server?

Sorry if the question is vague but I don't know a better way to ask and I didn't see the caveats/tradeoffs of the approach discussed here. I love the idea of accessing servers via keys, so that I ...
35
votes
2answers
4k views

Why do I have to edit /etc/sudoers with visudo?

I've noticed that the sudoers file and cron config files act in a special way compared to other config files on Linux. They need to be edited with a special wrapper rather than any text editor. Why is ...
27
votes
10answers
7k views

Why su to root instead of logging in as root?

I've heard often that it is better to su to root rather than log in directly as the root user (and of course people also say that it's even better to use sudo). I've never really understood why one ...
27
votes
5answers
14k views

Sudo as different user and running screen

Found out today that running screen as a different user that I sudo into won't work! i.e. ssh bob@server # ssh into server as bob sudo su "monitor" - screen (fails) I have a script that ...
23
votes
4answers
25k views

How to setup passwordless `sudo` on Linux?

How can passwordless sudo access be setup on either RHEL (Fedora, CentOS, etc) or Ubuntu distributions? (If it's the same across distros, that's even better!) Setting: personal and/or lab/training ...
23
votes
2answers
45k views

How can I allow one user to su to another without allowing root access?

I'd like to allow certain users to su to another user account without having to know that account's password, but not allow access to any other user account (i.e. root). For instance, I'd like to ...
22
votes
3answers
1k views

What are the actual benefits of assigning sudo privileges to a user instead of using root?

I am fairly new to server administration, and I have seen a lot of sites recommending to assign sudo privileges to a user created by the root user and giving the root user an insanely long password ...
21
votes
5answers
2k views

Can a program tell it is being run under sudo?

I have a program that should behave differently if it is being run under "sudo". Is there a way it can find out if it was run under sudo? Update: Someone asked why would I want to do this. In this ...
21
votes
4answers
4k views

vim re-edit as root

I often open a file in vim, make some changes and when it's time to save the file is read-only.. (owned by another user). I'm looking for tips on how I could re-open the file as root and keep my ...
18
votes
8answers
21k views

how to use xauth to run graphical application via other user on linux

My regular user account is, let's say, user1. I created separate user2 for some x application that i would like to run while being logged into x as user1 but in a way that will prevent it from ...
17
votes
12answers
10k views

How to pass alias through sudo

I have an alias that passes in some parameters to a tool that I use often. Sometimes I run as myself, sometimes under sudo. Unfortunately, of course, sudo doesn't recognise the alias. Does anyone ...
17
votes
4answers
4k views

How do I sudo over sshfs?

On my local host alpha I have a directory foo that is mapped via sshfs to host bravo as follows: $ sshfs charlie@bravo:/home/charlie ~/foo However, on host bravo there is another user, delta, that ...
13
votes
12answers
17k views

Why does sudo command take long to execute?

I've been picking up Linux (Fedora 10, then 11) over the past few months (and enjoying it immensely-- it's like discovering computers all over again, so many things to learn). I've added my user to ...
13
votes
4answers
3k views

Save file after forgetting to open as root / sudo vi [duplicate]

Possible Duplicate: vim re-edit as root I could have sworn I saw this question asked. But after looking though every search result for "vi" I'm stumped/lazy. I've opened a file, made an edit ...
13
votes
1answer
2k views

Changing the Sudo warning

The first time you try and sudo on a server you get the sudo warning; We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: ...
12
votes
2answers
649 views

Allow complex sudo command on Debian Linux

I need to allow a specific command on a Debian Linux box for a single user. I've tried this in the /etc/sudoers file: # User privilege specification zabbix ALL=NOPASSWD: /usr/bin/apt-get ...
12
votes
6answers
5k views

Why do I not have syntax highlighting when I sudo vi <filename>?

I don't understand how to allow syntax highlighting in files I'm editing via vi when using sudo. When I 'sudo vi ' the terminal is only black & white of my terminal settings. In vi if I enter ...
11
votes
6answers
16k views

su not working on mac os x?

I get this: Macintosh:8.4 TAmoyal$ su Password: su: Sorry Macintosh:8.4 TAmoyal$ I typed in the password I use for sudo. Why won't this work? Thanks!
11
votes
2answers
420 views

What is the difference between “sudo -i” and “sudo bash -l”

There is a recent question regarding multiple sysadmins working as root, and sudo bash -l was referenced. I searched for this on google and SE, but I don't understand the difference between sudo ...
10
votes
1answer
481 views

How can I implement ansible with per-host passwords, securely?

I would like to use ansible to manage a group of existing servers. I have created an ansible_hosts file, and tested successfully (with the -K option) with commands that only target a single host ...
9
votes
8answers
17k views

using su inside of a shell script

I'm automating a deploy process and I want to be able to just call one .sh file on my machine, have it do my build and upload the .zip to the server and then do a bunch of stuff on the server. One of ...
8
votes
4answers
669 views

`sudo echo “bla” >> /etc/sysctl.conf` permission denied

Disclaimer: I'm pretty novice at sysadmin stuff. I'm trying to set up port forwarding in an AWS EC2 instance, this has to be done in the command-line because I don't want to go in and edit anything, ...
8
votes
4answers
1k views

Update multiple sudoers file

We have multiple Linux servers that authenticate to an Active Directory Domain. For a group in AD, I want to add a list of commands that are allowed to run as root using sudo. I can obviously ssh-in ...
8
votes
2answers
6k views

How can I allow all users to run a given command via sudo?

I know how to create a command which a given user can execute via sudo. I have a given command I want to allow any user to be able to execute via sudo without entering a password. What would I put in ...
8
votes
6answers
6k views

How can I execute a bash function with sudo?

I have a bash function defined in a global bashrc, which requires root privileges to work. How can I run it with sudo, e.g. sudo myfunction. By default it gives an error: sudo: myfunction: command ...
8
votes
5answers
3k views

Log all commands run by admins on production servers

It is company policy for admins to login to the servers via a personal username, and then run sudo -i to become root. Upon running sudo -i, sudo will create an environmental variable called ...
8
votes
1answer
859 views

Configuring sudo to work without password

I'm trying to configure sudo to allow all users to restart apache without having to enter a password. Security concerns aside, why isn't this working? I added the line to /etc/sudoers: %admin ...
7
votes
9answers
9k views

Editing sudoers file to restrict a user's commands

Is it possible to edit the sudoers file so a user can use sudo for any command except for a specified one? I reverse is true, I believe, that the sudoers file can be setup so that a user can only ...
7
votes
3answers
390 views

We are transitioning from shared root password to using sudo. How do I audit usage of sudo?

When I came on board, all our SAs had to memorize the root password to the systems. I felt that this was cumbersome (when someone separates from the company, we had to touch every server and change ...
7
votes
3answers
676 views

Temporarlly increasing sudo's timeout for the duration of an install script

I'm trying to write a script, that will install a bunch of software, I'd like to not have to run everything as root, so I'd like to be able to prompt for a password and then go about the install, ...
6
votes
2answers
823 views

Why can the root user edit read-only files, but a regular user with sudo access can't?

If you try to append to a file with no write permissions (say, the /etc/sudoers file which is is owned by root and has 0440 permissions), if you're the actual root user, this works. However, if you're ...
6
votes
3answers
3k views

Running 'sudo' over SSH

I'm writing a script which is to log onto a bunch of remote machines and run a command on them. I've set up keys so the user running the script does not have to type the password of each machine, but ...
6
votes
2answers
4k views

How does `sudo` search the path for executables?

I am using rubygems (1.3.7) with gems that require root privileges on Ubuntu 10.10. When I compare my setup to an ubuntu 9.10 with rubygems 1.3.6 installation, I see the following difference in gem ...
6
votes
1answer
5k views

Repair a broken sudoers file [duplicate]

Possible Duplicate: Ubuntu : borked my sudoers file, how can I fix it? Problem description: I have broken my /etc/sudoers file by making a typo in it. Now I can no longer use any sudo ...
6
votes
1answer
363 views

How do I re-enable an sudo lecture, once it's been seen

I have sudo set to show the usual lecture on its first use by a user. Without thinking, I accidentally triggered its display for a new user as I was setting them up, and now it's been shown, they ...
6
votes
2answers
667 views

Sudoers file allow sudo on specific file for active directory group

I have active directory sign in working on an Ubuntu 12.04 box. When the user signs in, I have a script that runs that needs sudo permission (since it modifies the samba config file). How would I ...
6
votes
2answers
17k views

Debian: how to create a user with root privileges (sudo)

How do I create a user with root privileges in Debian? Maybe it sounds a bit silly, but I don't think I need user directories, only some rights to run services (mainly web server, mysql, etc.). I just ...
6
votes
1answer
1k views

Test whether a user has sudo privileges without requiring user input

I have a local shell script that performs a number of tests on a remote host, before delivering the payload; one of these tests being whether the user has sudo privileges, checked simply with sudo -v ...
5
votes
11answers
4k views

How can you prevent root password change on linux?

I'm setting up a server which other people will have sudo access to via ssh. They can install stuff and make changes as they see fit, however I still need to manage the server, install patches and ...
5
votes
2answers
1k views

Where does sudoer reports go?

So I'm testing out a small CentOS build (rackspace cloud). I set up my user and went to do some sudo'ing. Well, I forgot the step to add my user to the sudoers file with visudo. So of course, I get ...
5
votes
4answers
4k views

Ubuntu : borked my sudoers file, how can I fix it?

I was editing my /etc/sudoers file and saved it but it has a syntax error in there. Now I can't 'sudo vim /etc/sudoers' because sudo thinks the sudoers file is not valid. How can I fix this?
5
votes
5answers
12k views

ubuntu: let a user run a script with root permissions

I have ubuntu 8.04 and I want to write a bash script that runs as root which every user can run. I myself can do sudo. How do I do that? CLARIFICATION: I don't want to do it with sudo, because then ...
5
votes
5answers
4k views

Centralized sudo sudoers file?

I am the admin of several different servers and currently there is a different sudoers file on each one. This is getting slightly out of hand as quite often I need to give someone permissions to do ...
5
votes
2answers
682 views

How to add line to system configuration file with sudo?

I need add a line to a configuration file (e.g. /etc/resolv.conf). If I use sudo echo "nameserver 192.168.1.6" >> /etc/resolv.conf I get error message Access denied. Problem is that bash write ...
5
votes
2answers
2k views

should use sudo or just su root in server management?

Which approach is better? For desktop usage, it seems that sudo is better since: I can have a more consistent history as a normal user Don't need to remember two passwords, which is especially ...
5
votes
3answers
3k views

HOW TO: disable sudoer from editing /etc/sudoers file?

How can I prevent a sudoer from editing the /etc/sudoer file?
5
votes
2answers
455 views

In Ubuntu can root overwrite any file?

I am on Ubuntu 10.04.02. I thought that when using sudo that would execute commands as root. But here as root I cannot write to my own file. Is this correct? ...
5
votes
3answers
1k views

sudo or acl or setuid/setgid?

for a reason I do not really understand, everyone wants sudo for all and everything. At work we even have as many entries as there are way to read a logfile (head/tail/cat/more, ...). I think, sudo ...
5
votes
5answers
3k views

Every single time I use sudo it hangs before completing

Whether I get prompted for a password or not, it hangs between accepting the authentication and executing what I asked for. E.G. sudo ls will hang for about 60 seconds. I'm confused about what might ...