生成使用者賬戶密碼的shell

2021-08-20 04:16:06 字數 2096 閱讀 5761

這是乙個新增使用者的小指令碼,詳情請看**的注釋

#!/bin/bash

## @author enum.lin

## @desc

這是乙個自動生成使用者和密碼,並可以將使用者新增到

sudoers

列表中的

shell

#########

需要root

的許可權執行

## 帶錯誤資訊的退出函式

##############

functionexitwitherrormsg()

# 收集使用者名稱

echo

"please input your username..."

read

username

# 檢測使用者是否存在

user_count=`cat

/etc/passwd | grep

"^$username:" -c`

if [$user_count-ne0];thenexitwitherrormsg

"the account [$username] is exist.";

fi#

收集使用者密碼

echo

"please first input your paassword..."

read

-s firstpassword

echo

"please second input your username..."

read

-s secondpassword

# 檢查兩次密碼輸入是否一致

if [$firstpassword!=$secondpassword];thenexitwitherrormsg

"two input password is not sample!\ninput andy key exit shell...";

fi#

是否加入到

sudoers

檔案中echo

"is add to sudoers

【yes/no

】?no"

read

issudoer

# 新增和修改使用者密碼

adduser

$username

echo

"$firstpassword" | passwd

--stdin "$username"

# 新增到

sudoers

列表if ["$issudoer"

="yes"

];thensudo

echo "$username all=(all:all) all"

>> /etc/sudoers

echo

"add user into sudoers list"

fi##

生成報告

echo

"create user is success!"

echo

-e "username:$username\npaassword:$firstpassword\nadd2sudoerflag:$issudoer"

echo

"輸入任意鍵,退出介面,退出前,請儲存好生成的賬號密碼!

"read

anykey

刪除使用者賬戶密碼

windows system32 config sam 將以上sam檔案刪除後所有的使用者密碼都會無效 如果你是系統管理員,而且其它使用者沒有進行設定的話,直接選擇開始選單 設定 使用者帳戶 進入修改密碼後,第一項輸入你的原密碼,後面兩項要求你 輸入新密碼 和 重複新密碼 這兩項空著什麼都不輸就可以...

Shell指令碼批量建立使用者並隨機生成密碼

要求 批量建立10個系統賬號oldboy01 oldboy10,並設定生成密碼 密碼不同 實現指令碼 bin bash question3 for i in seq w 10 do useradd s bin bash oldboy i echo password i md5sum tee a pa...

MAC更改原有使用者賬戶密碼

今天搞到一台mac,不過沒有開機密碼 不是偷的 於是按照下面的方法做了,竟然真的重置了開機密碼 新建乙個管理員賬戶來更改原有使用者賬戶密碼 開機,啟動時按cmd s,進入single user mode,在 root 下 輸入 mount uaw 回車,輸入reboot重新啟動。你會發現,熟悉的初始...