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

learn more… | top users | synonyms

57
votes
8answers
21k views

ssh-agent forwarding and sudo to another user

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 ...
40
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 ...
37
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 ...
36
votes
6answers
16k 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 ...
31
votes
5answers
33k 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 ...
28
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 ...
23
votes
4answers
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 ...
23
votes
2answers
49k 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
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 ...
21
votes
8answers
25k 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 ...
18
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 ...
17
votes
12answers
11k 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
3answers
2k 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 ...
15
votes
1answer
3k 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: ...
14
votes
13answers
20k 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 ...
14
votes
6answers
6k 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 ...
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
6answers
18k 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!
13
votes
3answers
487 views

Which method to use for granting sudo

What is the difference between adding a user to /etc/sudoers and usermod -a -G sudo? Which method should be used for granting sudo?
13
votes
5answers
5k 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 ...
12
votes
2answers
761 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 ...
11
votes
2answers
493 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 ...
9
votes
8answers
18k 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 ...
9
votes
6answers
7k 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 ...
9
votes
3answers
818 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, ...
8
votes
4answers
1k 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
468 views

Symbolic link and sudo

I create a symbolic link: ln -s /tmp/folder1 /tmp/folder2 Then I go to /tmp/folder2 and run pwd: $ cd /tmp/folder2/ $ pwd /tmp/folder2 $ sudo pwd /tmp/folder1 # <-- This is the odd part Why ...
8
votes
9answers
10k 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 ...
8
votes
2answers
7k 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
1answer
899 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
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?
7
votes
3answers
417 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
1answer
214 views

Linux/Unix - /etc/sudoers - host definition

can anybody tell me in which case the sudo host definition is useful? I mean this part of a line in the sudoers file: bob host1 = NOPASSWD: reboot In which environment (except sudo via LDAP) do I ...
6
votes
2answers
785 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 ...
6
votes
2answers
3k 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 ...
6
votes
2answers
911 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
3answers
1k views

User name before sudo

I got a script requiring sudo, but the script must set parameters according to the original user, such as: chown "${USER}:${USER}" dir If I set it under sudo, I just end up with chmod root:root, ...
6
votes
2answers
2k views

How to grant sudo rights only to specific script files?

I would like a user to have sudo rights (without password check) to a couple of shell scripts under a specific directory (in my case, /usr/local/tomcat7/bin), and to nowhere else. What's the simplest ...
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
6k 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
922 views

AWS - removing ec2-user from sudo list

I'm running a production-level Amazon ec2 instance, and I want to close out root privileges to all users. Normally, when one logs in to the instance as ec2-user, the ec2-user immediately gets sudo ...
6
votes
1answer
406 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
354 views

Creating a pseudoterminal to make sudo happy

I need to automate the provisioning of a cloud instance (running Fedora 17) for which the following initial facts are true: I have ssh-key based access to a remote user (cloud) That user has ...
6
votes
2answers
835 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
20k 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
3answers
2k 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
5k 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 ...