添加新Admin用戶
參考:How to Change Linux User’s Password in One Command Line
假設(shè)我們要添加一個(gè)用戶test
:
# 添加用戶
$ sudo adduser test
# 根據(jù)交互揩慕,填寫密碼和默認(rèn)信息
#...
# 將用戶添加到sudoer權(quán)限組
$ sudo usermod -aG sudo test
# 切換到用戶
$ su - test
在root
用戶下無交互模式創(chuàng)建新用戶test
:
useradd -s /bin/bash test
usermod -aG sudo test
echo -e "test123\ntest123" | passwd test
su - test
在本機(jī)通過ssh一鍵添加sudo用戶并創(chuàng)建密碼:
ssh root@IP 'useradd -s /bin/bash test; usermod -aG sudo test; echo -e "test123\ntest123" | passwd test' && echo '[ OK ]'
記住迎卤,如果是在腳本里面,引號必須用雙引號"
蜗搔,而不能單引號!
pass="test123"
echo -e "${pass}\n${pass}" | passwd test