Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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

Using the user defined bash script to create groups and users

\#\!/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; echo "failed to create user"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit
&nbsp;&nbsp; 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; echo "failed to create user"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit
&nbsp;&nbsp; fi
fi
  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.