Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page describes how the current servers access & permissions are setup.

Using the user-defined bash script to create groups and users

...

. I avoid putting sudo instructions in the script because the file /etc/sudoers is sensitive to edit and should only be edit by su -c visudo

No Format

#!/bin/bash
\# Author: Henry Jiang
\# Script: setupAccess
\# Summary: set up groups and users
\# Syntax: setupAccess.sh <group> <user>

if \[\[ \! $# > 0 \]\]
then
&nbsp;&nbsp;   echo "Usage: setupAccess <group> <user> "
&nbsp;&nbsp;
   exit
fi
if \[\[ $# == 0 \]\]
then
&nbsp;&nbsp;
   echo "Please specify a group name"
&nbsp;&nbsp;   exit
fi
if \[\[ $# == 1 \]\]
then
&nbsp;&nbsp;   echo "Please specify a user name"
&nbsp;&nbsp;
   exit
fi

group="$1"
user="$2"
defaultpass="newpass"
password=`openssl passwd $defaultpass`

if \[\[ \! $? == 0 \]\]
then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        echo "openssl not installed\!"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        exit
fi
\#Try to create the group, if it already exist, add user to group
groupadd \-r $group

if \[\[ \! $? == 0 \]\]
then
&nbsp;&nbsp;
   echo "Group $group already exists, adding user: $user to group."
&nbsp;&nbsp;
   useradd \-g $group \-p $password \-d /home/$user&nbsp;  \-m $user
&nbsp;&nbsp;   if \[\[ $? == 0 \]\]
&nbsp;&nbsp;   then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        echo "User '$user' added to group '$group' with default password '$defaultpass'"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit
&nbsp;&nbsp; else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        exit
   else
        echo "failed to create user"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit
&nbsp;&nbsp;
        exit
   fi
else
&nbsp;&nbsp;   echo "Group $group has been created, creating user: $user ..."
&nbsp;&nbsp;
   useradd \-g $group \-p $password \-d /home/$user&nbsp;  \-m $user
&nbsp;&nbsp;   if \[\[ $? == 0 \]\]
&nbsp;&nbsp;
   then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        echo "User '$user' added to group '$group' with default password '$defaultpass'"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit
&nbsp;&nbsp; else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        exit
   else
        echo "failed to create user"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit
&nbsp;&nbsp; fi
fi

        exit
   fi
fi

The above script is located at root's home folder(~), only root have permissions to rwx this file.

Setting up groups, users, and sudo on servers

DB

[root@CentOSDB17882 ~]# ./setupAccess.sh dbadmin henry

Group webadmin has been created, creating user: henry ...
User 'henry' added to group 'webadmin' with default password 'newpass'

WEB

[root@CentOSWeb17881 ~]# ./setupAccess.sh webadmin henry

Group webadmin has been created, creating user: henry ...

User 'henry' added to group 'webadmin' with default password 'newpass'

GEO

[root@CentOSGeo17883 ~]# ./setAccess.sh geoadmin henry
Group geoadmin has been created, creating user: henry ...
User 'henry' added to group 'geoadmin' with default password 'newpass'

Add group to sudoers

[root@CentOSGeo17883 ~]# su -c visudo

scroll to the bottom and add

No Format

## reboot, add any additional commands here
Cmnd_Alias USER_DEFINED = /sbin/reboot

## sudo commands allowed for geo admins
%geoadmin       ALL = SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, USER_DEFINED

Same for other servers.

Groups for developers are also setup in the same manner:

For DB:

[root@CentOSDB17882 ~]# ./setupAccess.sh dbdev paul