Skip to main content

Initial Settings : Sudo Settings

 Configure Sudo to separate users' duty if some people share privileges.

It does not need to install sudo manually because it is installed by default even if Minimal installed environment.

[1]. Transfer root privilege all to a user.

[root@dlp ~]# visudo

# add to the end: user [cent] can use all root privilege

cent  ALL=(ALL)       ALL

# how to write ⇒ destination host=(owner) command

# verify with user [cent]

[cent@dlp ~]$ /usr/bin/cat /etc/shadow

/usr/bin/cat: /etc/shadow: Permission denied   # denied normally

[cent@dlp ~]$ sudo /usr/bin/cat /etc/shadow

Password:     # user's own password

.....

.....

chrony:!!:18163::::::

tcpdump:!!:18163::::::   # just executed

[2]. In addition to the setting of [1], set some commands prohibit.

[root@dlp ~]# visudo

# line 49: add

# for example, set aliase for the kind of shutdown commands

Cmnd_Alias SHUTDOWN = /usr/sbin/halt, /usr/sbin/shutdown, \

/usr/sbin/poweroff, /usr/sbin/reboot, /usr/sbin/init, /usr/bin/systemctl


# add ( prohibit commands in aliase [SHUTDOWN] )

cent  ALL=(ALL)       ALL, !SHUTDOWN


# verify with user [cent]

[cent@dlp ~]$ sudo /usr/sbin/reboot

[sudo] password for cent:

Sorry, user cent is not allowed to execute '/usr/sbin/reboot' as root on dlp.srv.world.   # denied normally

[3]. Transfer some commands with root privilege to users in a group.

[root@dlp ~]# visudo

# line 51: add

# for example, set aliase for the kind of user managment commands

Cmnd_Alias USERMGR = /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod, \

/usr/bin/passwd


# add to the end

%usermgr ALL=(ALL) USERMGR

[root@dlp ~]# groupadd usermgr

[root@dlp ~]# usermod -G usermgr redhat

# verify with user [redhat]

[redhat@dlp ~]$ sudo /usr/sbin/useradd testuser

[redhat@dlp ~]$ sudo /usr/bin/passwd testuser

Changing password for user testuser.

New UNIX password:

Retype new UNIX password:

passwd: all authentication tokens updated successfully.   # just executed

[4]. Transfer a command with root privilege to a user.

[root@dlp ~]# visudo

# add to the end: settings for each user

fedora  ALL=(ALL)       /usr/sbin/visudo

ubuntu  ALL=(ALL)       /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod, /usr/bin/passwd

debian  ALL=(ALL)       /usr/bin/vi


# for example, verify with user [fedora]

[fedora@dlp ~]$ sudo /usr/sbin/visudo

## Sudoers allows particular users to run various commands as

## the root user, without needing the root password.

##   # just executed

[5]. The logs for sudo are kept in [/var/log/secure], but there are many kind of logs in it. So if you'd like to keep only Sudo logs in another file, Configure like follows.

[root@dlp ~]# visudo

# add to the end

# for example, output logs to [local1] facility

Defaults syslog=local1

[root@dlp ~]# vi /etc/rsyslog.conf

# line 46,47: add like follows

*.info;mail.none;authpriv.none;cron.none;local1.none   /var/log/messages

local1.*                /var/log/sudo.log


# The authpriv file has restricted access.

authpriv.*              /var/log/secure


[root@dlp ~]# systemctl restart rsyslog

Comments

Post a Comment

Popular posts from this blog

Unix / Linux - Special Variables

W e will discuss in detail about special variable in Unix. In one of our previous chapters, we understood how to be careful when we use certain nonalphanumeric characters in variable names. This is because those characters are used in the names of special Unix variables. These variables are reserved for specific functions. For example, the  $  character represents the process ID number, or PID, of the current shell − $echo $$ The above command writes the PID of the current shell − 29949 The following table shows a number of special variables that you can use in your shell scripts − Command-Line Arguments The command-line arguments $1, $2, $3, ...$9 are positional parameters, with $0 pointing to the actual command, program, shell script, or function and $1, $2, $3, ...$9 as the arguments to the command. Following script uses various special variables related to the command line − #!/bin/sh echo "File Name: $0" echo "First Parameter : $1" echo "Second Parameter :...

LINUX List files and directories using SSH

In order to list all files and directories using an SSH client, you would need to execute the appropriate command. The command name, in this case, is ls and it accepts various parameters. When using the command alone (without arguments): ls the output will be all visible files and folders without additional formatting or information. In order to view more information about the files (such as their permissions, ownership, last modified date, etc) and at the same time to list the files and directories, you would need to supply additional arguments to the command. The most common arguments are as follows: ls –a(Short from –all) Lists all files and folders including hidden (starting with a dot) files and directories. ls –R (Short from –Recursive) Lists recursively (i.e follows subfolders as well) all files and folders under the current directory. ls -l (Short from –long) Lists all files and folders, each on a separate line, and provides additional information about them (permission...

Initial Settings : Vim Settings

 There are many cases to use text editor on CUI terminal, so it's more convenient to install editors with advanced features like Vim. [1]. Install Vim in this example. [root@dlp ~]# dnf -y install vim-enhanced [2]. Set command alias for your own environment. But for users that has UID 201 or higher, Alias is already set by [/etc/profile.d/vim.sh] file that is included in [vim-enhanced] package. [root@dlp ~]# vi ~/.bashrc # add alias to the end alias vi='vim' # apply changes [root@dlp ~]# source ~/.bashrc [3]. Configure Vim for your own environment. (common settings for all users are in [/etc/vimrc]) [root@dlp ~]# vi ~/.vimrc " use extended function of vim (no compatible with vi) set nocompatible " specify encoding set encoding=utf-8 " specify file encoding set fileencodings=utf-8,iso-2022-jp,sjis,euc-jp " specify file formats set fileformats=unix,dos " take backup " if not, specify [ set nobackup ] set backup " specify backup directo...