mirror of
https://github.com/darksaid98/ubuntu-server-setup.git
synced 2026-12-03 06:28:58 +00:00
Remove the need for prompting the user for a password (#12)
Relates to issue #9
This commit is contained in:
1 parent
ce73240765
commit
153087929c
4 files changed
+5
-27
No files matched your search
@@ -31,7 +31,7 @@ bash setup.sh
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Setup prompts
|
# Setup prompts
|
||||||
When the setup script is run, you will be prompted to enter the username and password of the new user account.
|
When the setup script is run, you will be prompted to enter the username of the new user account.
|
||||||
|
|
||||||
Following that, you will then be prompted to add a public ssh key (which should be from your local machine) for the new account. To generate an ssh key from your local machine:
|
Following that, you will then be prompted to add a public ssh key (which should be from your local machine) for the new account. To generate an ssh key from your local machine:
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -20,12 +20,10 @@ output_file="output.log"
|
|||||||
function main() {
|
function main() {
|
||||||
read -rp "Enter the username of the new user account:" username
|
read -rp "Enter the username of the new user account:" username
|
||||||
|
|
||||||
promptForPassword
|
|
||||||
|
|
||||||
# Run setup functions
|
# Run setup functions
|
||||||
trap cleanup EXIT SIGHUP SIGINT SIGTERM
|
trap cleanup EXIT SIGHUP SIGINT SIGTERM
|
||||||
|
|
||||||
addUserAccount "${username}" "${password}"
|
addUserAccount "${username}"
|
||||||
|
|
||||||
read -rp $'Paste in the public SSH key for the new user:\n' sshKey
|
read -rp $'Paste in the public SSH key for the new user:\n' sshKey
|
||||||
echo 'Running setup script...'
|
echo 'Running setup script...'
|
||||||
@@ -89,21 +87,4 @@ function setupTimezone() {
|
|||||||
echo "Timezone is set to $(cat /etc/timezone)" >&3
|
echo "Timezone is set to $(cat /etc/timezone)" >&3
|
||||||
}
|
}
|
||||||
|
|
||||||
# Keep prompting for the password and password confirmation
|
|
||||||
function promptForPassword() {
|
|
||||||
PASSWORDS_MATCH=0
|
|
||||||
while [ "${PASSWORDS_MATCH}" -eq "0" ]; do
|
|
||||||
read -s -rp "Enter new UNIX password:" password
|
|
||||||
printf "\n"
|
|
||||||
read -s -rp "Retype new UNIX password:" password_confirmation
|
|
||||||
printf "\n"
|
|
||||||
|
|
||||||
if [[ "${password}" != "${password_confirmation}" ]]; then
|
|
||||||
echo "Passwords do not match! Please try again."
|
|
||||||
else
|
|
||||||
PASSWORDS_MATCH=1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
main
|
main
|
||||||
+2
-4
@@ -3,12 +3,10 @@
|
|||||||
# Add the new user account
|
# Add the new user account
|
||||||
# Arguments:
|
# Arguments:
|
||||||
# Account Username
|
# Account Username
|
||||||
# Account Password
|
|
||||||
# Flag to determine if user account is added silently. (With / Without GECOS prompt)
|
# Flag to determine if user account is added silently. (With / Without GECOS prompt)
|
||||||
function addUserAccount() {
|
function addUserAccount() {
|
||||||
local username=${1}
|
local username=${1}
|
||||||
local password=${2}
|
local silent_mode=${2}
|
||||||
local silent_mode=${3}
|
|
||||||
|
|
||||||
if [[ ${silent_mode} == "true" ]]; then
|
if [[ ${silent_mode} == "true" ]]; then
|
||||||
sudo adduser --disabled-password --gecos '' "${username}"
|
sudo adduser --disabled-password --gecos '' "${username}"
|
||||||
@@ -16,8 +14,8 @@ function addUserAccount() {
|
|||||||
sudo adduser --disabled-password "${username}"
|
sudo adduser --disabled-password "${username}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${username}:${password}" | sudo chpasswd
|
|
||||||
sudo usermod -aG sudo "${username}"
|
sudo usermod -aG sudo "${username}"
|
||||||
|
sudo passwd -d "${username}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add the local machine public SSH Key for the new user account
|
# Add the local machine public SSH Key for the new user account
|
||||||
|
|||||||
+1
-2
@@ -23,7 +23,6 @@ source "${current_dir}/lib/bunit.shl"
|
|||||||
source "${current_dir}/../setupLibrary.sh"
|
source "${current_dir}/../setupLibrary.sh"
|
||||||
|
|
||||||
test_user_account=testuser
|
test_user_account=testuser
|
||||||
test_account_password="123%pass_321"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
VERBOSE_MODE="true"
|
VERBOSE_MODE="true"
|
||||||
@@ -32,7 +31,7 @@ VERBOSE_MODE="true"
|
|||||||
|
|
||||||
function testSetup () {
|
function testSetup () {
|
||||||
echo "Test Setup"
|
echo "Test Setup"
|
||||||
addUserAccount ${test_user_account} ${test_account_password} true
|
addUserAccount ${test_user_account} true
|
||||||
}
|
}
|
||||||
|
|
||||||
function testUserAccountCreated() {
|
function testUserAccountCreated() {
|
||||||
|
|||||||
Reference in new issue
Block a user