Friday 8 July 2016

Some tricks with sudo!

Sudo is a command/utility that allows a permitted user to execute a command as the superuser or another user, as specified in the /etc/sudoers file.
The real and effective uid and gid are set to match those of the target user as specified in the passwd file.
By default, sudo requires that users authenticate themselves with a password.
Sudo can log both successful and unsuccessful attempts  to syslog or another log file which can be modified via entries in /etc/syslog.conf.

This post isn't intented to explain the detailed working of sudo & how it encorporates user aliases & command aliases to provide a granular set of forged permissions.
The purpose of this post is to provide a couple of tricks when faced with some common sudo related problems:

A user is unable to switch to root user & run a command due to terminal error:

To fix this problem enter the following lines in /etc/sudoers file:

Defaults:<username> !requiretty
<username> ALL=NOPASSWD: /bin/su - -c *

To run a command via sudo on a remote server through a ssh connection:

This normally works right out of the box but sometimes you get an error saying:

sudo: sorry, you must have a tty to run sudo

In case you get the above error try the following command line as an example :-

ssh -tt server  'uname -a; sudo ifconfig -a'

The command should run successfully now.

A user needs to be able to switch to to another user using sudo:

In order to accomplish this enter the following line sudoers file:-

source_user ALL=(ALL) NOPASSWD: /bin/su - destination_user

No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...