-
Notifications
You must be signed in to change notification settings - Fork 989
shell scripting project #1 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
norfluxX
wants to merge
11
commits into
LondheShubham153:main
Choose a base branch
from
norfluxX:proj1-shell-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bd99c61
shell scripting project #1
norfluxX 89b33c2
Add pam-main.sh with recommended changes
norfluxX 8a74275
Fixed while loop validation and safer delete guard in pam-main.sh
norfluxX 115dd6a
Fixed break to continue in pam-main.sh
norfluxX 1c2c1e9
Update pam-main.sh
norfluxX 373a869
Update pam-main.sh
norfluxX c6aaf8c
modified pam-main.sh with working enchancements
norfluxX 0dca2ad
Merge branch 'proj1-shell-script' of https://github.com/norfluxX/Shel…
norfluxX 70d4b4c
modified pam-main.sh with working enchancements
norfluxX e2a9eec
modified pam-main.sh with backup validation
norfluxX 0edfd17
modified pam-main.sh to make nologin more stealth
norfluxX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| #/bin/bash | ||
| #!/usr/bin/bash | ||
| # Date: 10/09/2025 | ||
| # This is script for user & group management in linux. | ||
| # Usage: pam-main.sh | ||
| # Author: Bhikesh Khute | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| WHITE='\033[1;37m' | ||
| PURPLE='\033[0;35m' | ||
| CYAN='\033[0;36m' | ||
| NC='\033[0m' | ||
| echo "------------------------------------------------------" | ||
| echo -e "=======\033[45m Welcome to Login Management System \033[0m=======" | ||
| echo "------------------------------------------------------" | ||
| while true; do | ||
norfluxX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo -e "${RED}1. Add user${NC}" | ||
| echo -e "${GREEN}2. Delete user${NC}" | ||
| echo -e "${PURPLE}3. Modify user - Add user to multiple groups${NC}" | ||
| echo -e "${CYAN}4. Modify user - Changing Login Shell${NC}" | ||
| echo -e "${YELLOW}5. Modify user - Disable Login${NC}" | ||
| echo -e "${GREEN}6. Modify user - Enable Login${NC}" | ||
| echo -e "${CYAN}7. Modify user - Add user to sudo group${NC}" | ||
| echo -e "${RED}8. Add group${NC}" | ||
| echo -e "${GREEN}9. Backup directories${NC}" | ||
| echo -e "${PURPLE}10. Exit${NC}" | ||
| read -p "Select the option: " choice | ||
| case $choice in | ||
| 1) | ||
| read -p "Enter first and last name of the user(Example - Ramesh Sippy): " fullname #Example - Ramesh Sippy | ||
| username=`echo $fullname | awk '{print tolower($1 $2)}'` #Output - rameshsippy | ||
| useradd -c "$fullname" -m -s /bin/bash $username > /dev/null #Redirects output to blackhole instead of screen | ||
| echo $username:R@nd0mDig!t | chpasswd #Adding Default Password; To be changed after login for security reasons. | ||
| passwd --expire $username > /dev/null #Password is expired so that on first login itself it can be changed. | ||
| echo "$username is successfully created in the system" | ||
norfluxX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "-----------------------------------------------" | ||
| unset username | ||
| ;; | ||
| 2) | ||
| awk -F: '$3 >= 1000 {print $1}' /etc/passwd | nl -w1 -s". " #Filtering only normal users | ||
| read -p "Select user to be deleted: " choice | ||
| username=$(awk -F: '$3 >= 1000 {print $1}' /etc/passwd | sed -n "${choice}p") | ||
| deluser --remove-home -q $username | ||
| echo "$username is successfully deleted from the system" | ||
| echo "-------------------------------------------------" | ||
| unset username | ||
| unset choice | ||
| ;; | ||
norfluxX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 3) | ||
| echo "------------------Normal Users List------------------" | ||
| awk -F: '$3 >= 1000 {print $1}' /etc/passwd | nl -w1 -s". " #Filtering only normal users | ||
| echo "------------------Group List-------------------------" | ||
| awk -F: '$3 >= 1000 {print $1}' /etc/group | nl -w1 -s". " | ||
| read -p "Select the existing user: " choice | ||
| read -p "Select the group name to be added: " gchoice | ||
| username=$(awk -F: '$3 >= 1000 {print $1}' /etc/passwd | sed -n "${choice}p") | ||
| grpname=$(awk -F: '$3 >= 1000 {print $1}' /etc/group | sed -n "${gchoice}p") | ||
| usermod -aG $grpname $username | ||
| echo "$username is successfully added to group $grpname" | ||
| echo "-------------------------------------------------" | ||
norfluxX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| unset grpname | ||
| unset username | ||
| unset choice | ||
| unset gchoice | ||
| ;; | ||
| 4) | ||
| echo "------------------Normal Users List------------------" | ||
| awk -F: '$3 >= 1000 {print $1}' /etc/passwd | nl -w1 -s". " #Filtering only normal users | ||
| read -p "Select the existing username: " choice | ||
| username=$(awk -F: '$3 >= 1000 {print $1}' /etc/passwd | sed -n "${choice}p") | ||
| curr_shell=$(getent passwd "$username" | cut -d: -f7) | ||
| if [ "$curr_shell" = "/bin/sh" ]; then | ||
| chsh -s /bin/bash "$username" | ||
| echo "$username's shell is successfully changed to bash" | ||
| echo "-------------------------------------------------" | ||
| elif [ "$curr_shell" = "/bin/bash" ]; then | ||
| chsh -s /bin/sh "$username" | ||
| echo "$username's shell is successfully changed to sh" | ||
| echo "-----------------------------------------------" | ||
| fi | ||
norfluxX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| unset username | ||
| unset curr_shell | ||
| unset choice | ||
| ;; | ||
| 5) | ||
| echo "------------------Normal Users List------------------" | ||
| awk -F: '$3 >= 1000 {print $1}' /etc/passwd | nl -w1 -s". " #Filtering only normal users | ||
| read -p "Select the existing username: " choice | ||
| username=$(awk -F: '$3 >= 1000 {print $1}' /etc/passwd | sed -n "${choice}p") | ||
| if getent passwd "$username" > /dev/null; then | ||
| echo "Changing $username shell to /usr/sbin/nologin" | ||
| chsh -s /usr/sbin/nologin "$username" | ||
| echo "$username's disabled to nologin" | ||
| echo "-------------------------------" | ||
| else | ||
| echo "User $username not found!" | ||
| fi | ||
| unset username | ||
norfluxX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| unset choice | ||
| ;; | ||
| 6) | ||
| echo "------------------Normal Users List------------------" | ||
| awk -F: '$3 >= 1000 {print $1}' /etc/passwd | nl -w1 -s". " #Filtering only normal users | ||
| read -p "Select the existing username: " choice | ||
| username=$(awk -F: '$3 >= 1000 {print $1}' /etc/passwd | sed -n "${choice}p") | ||
| if getent passwd "$username" > /dev/null; then | ||
| echo "Changing $username shell to /bin/bash" | ||
| chsh -s /bin/bash "$username" | ||
| echo "$username's shell is successfully activated to bash" | ||
| echo "---------------------------------------------------" | ||
| else | ||
| echo "User $username not found!" | ||
| fi | ||
| unset username | ||
| unset choice | ||
| ;; | ||
| 7) | ||
| echo "------------------Normal Users List------------------" | ||
| awk -F: '$3 >= 1000 {print $1}' /etc/passwd | nl -w1 -s". " #Filtering only normal users | ||
| read -p "Enter the existing username: " choice | ||
| username=$(awk -F: '$3 >= 1000 {print $1}' /etc/passwd | sed -n "${choice}p") | ||
| usermod -aG sudo $username | ||
| echo "$username is successfully added to sudo group. Enjoy super-privileges!" | ||
| echo "----------------------------------------------------------------------" | ||
norfluxX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| unset username | ||
| unset choice | ||
| ;; | ||
| 8) | ||
| read -p "Enter the group name to be added: " grpname | ||
| addgroup $grpname > /dev/null | ||
| echo "--------------------$grpname is added in the system.------------------" | ||
| echo " " | ||
| ;; | ||
norfluxX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 9) | ||
| mkdir -p /opt/dir_backups | ||
| read -p "Select the username to intiate the backup: " choice | ||
| username=$(awk -F: '$3 >= 1000 {print $1}' /etc/passwd | sed -n "${choice}p") | ||
| read -p "Specify the path of the directory to be backuped up: " dirback | ||
| tar -cvzf /opt/dir_backups/$username.tar.gz $dirback > /dev/null | ||
| echo "Backup completed successfully" | ||
| echo "-----------------------------" | ||
| unset username | ||
norfluxX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| unset dirback | ||
| unset choice | ||
norfluxX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ;; | ||
| 10) | ||
| break; | ||
| ;; | ||
| *) | ||
| echo "Invalid option! Exiting the program" | ||
| esac | ||
| done | ||
norfluxX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.