[shell script] 사용자 추가 및 삭제 Linux



1. 사용자 추가 script

# vi adduser    <- chmod 700 adduser


#!/bin/bash
# Script to add a user to Linux system
clear

if [ $(id -u) -eq 0 ]; then
        echo ====================================
        echo "        UserAdd Process           "
        echo ====================================
        read -p "Enter username : " username
        read -s -p "Enter password : " password
        egrep "^$username" /etc/passwd >/dev/null
        if [ $? -eq 0 ]; then
                echo "$username exists!"
                exit 1
        else
                pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
                useradd -m -p $pass $username -s /sbin/nologin
                [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
        fi
else
        echo "Only root may add a user to the system"
        exit 2
fi


2. 사용자 삭제 script

# vi deluser    <- chmod 700 deluser

#/bin/bash
read -p "Enter a User name to delete :" username
grep $username /etc/passwd >/dev/null

[ "$username" == "root" ] && exit 1 || :

if [ $? -eq 0 ]; then
        deluser $username
        echo "User $username has been deleted"
else
        echo "User $username not found"
fi








덧글

댓글 입력 영역



통계 위젯 (블랙)

220
78
353266

이 이글루를 링크한 사람 (화이트)

2

google

구글_이글루스_사이드