mirror of
https://github.com/darksaid98/ubuntu-server-setup.git
synced 2026-12-03 14:38:57 +00:00
Enables one to run setup without creating a new user by using a second non-root account (#15)
* Enable one to choose to use an existing second non-root account for configuring the server. * Current user by def * Changed default TimeZone and added a more secure ssh key derivation method according to https://blog.peterruppel.de/ed25519-for-ssh/ * Refactor setup scripts Co-authored-by: BreakSecurity <[email protected]>
This commit is contained in:
1 parent
8c4f801e10
commit
7beaeed0cd
3 files changed
+26
-5
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
[](https://travis-ci.org/jasonheecs/ubuntu-server-setup)
|
[](https://travis-ci.org/jasonheecs/ubuntu-server-setup)
|
||||||
|
|
||||||
This is a setup script to automate the setup and provisioning of Ubuntu servers. It does the following:
|
This is a setup script to automate the setup and provisioning of Ubuntu servers. It does the following:
|
||||||
* Adds a new user account with sudo access
|
* Adds or updates a user account with sudo access
|
||||||
* Adds a public ssh key for the new user account
|
* Adds a public ssh key for the new user account
|
||||||
* Disables password authentication to the server
|
* Disables password authentication to the server
|
||||||
* Deny root login to the server
|
* Deny root login to the server
|
||||||
@@ -35,8 +35,8 @@ When the setup script is run, you will be prompted to enter the username of the
|
|||||||
|
|
||||||
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
|
||||||
ssh-keygen -t rsa
|
ssh-keygen -t ed25519 -a 200 -C "user@server" -f ~/.ssh/user_server_ed25519
|
||||||
cat ~/.ssh/id_rsa.pub
|
cat ~/.ssh/user_server_ed25519.pub
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, you will be prompted to specify a [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for the server. It will be set to 'Asia/Singapore' if you do not specify a value.
|
Finally, you will be prompted to specify a [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for the server. It will be set to 'Asia/Singapore' if you do not specify a value.
|
||||||
|
|||||||
@@ -18,18 +18,29 @@ includeDependencies
|
|||||||
output_file="output.log"
|
output_file="output.log"
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
read -rp "Enter the username of the new user account:" username
|
read -rp "Do you want to create a new non-root user? (Recommended) [Y/N] " createUser
|
||||||
|
|
||||||
# Run setup functions
|
# Run setup functions
|
||||||
trap cleanup EXIT SIGHUP SIGINT SIGTERM
|
trap cleanup EXIT SIGHUP SIGINT SIGTERM
|
||||||
|
|
||||||
addUserAccount "${username}"
|
if [[ $createUser == [nN] ]]; then
|
||||||
|
username=$(whoami)
|
||||||
|
updateUserAccount "${username}"
|
||||||
|
elif [[ $createUser == [yY] ]]; then
|
||||||
|
read -rp "Enter the username of the new user account: " username
|
||||||
|
addUserAccount "${username}"
|
||||||
|
else
|
||||||
|
echo 'This is not a valid choice!'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
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...'
|
||||||
logTimestamp "${output_file}"
|
logTimestamp "${output_file}"
|
||||||
|
|
||||||
exec 3>&1 >>"${output_file}" 2>&1
|
exec 3>&1 >>"${output_file}" 2>&1
|
||||||
|
|
||||||
|
|
||||||
disableSudoPassword "${username}"
|
disableSudoPassword "${username}"
|
||||||
addSSHKey "${username}" "${sshKey}"
|
addSSHKey "${username}" "${sshKey}"
|
||||||
changeSSHConfig
|
changeSSHConfig
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Update the user account
|
||||||
|
# Arguments:
|
||||||
|
# Account Username
|
||||||
|
function updateUserAccount() {
|
||||||
|
local username=${1}
|
||||||
|
|
||||||
|
sudo passwd -d "${username}"
|
||||||
|
sudo usermod -aG sudo "${username}"
|
||||||
|
}
|
||||||
|
|
||||||
# Add the new user account
|
# Add the new user account
|
||||||
# Arguments:
|
# Arguments:
|
||||||
# Account Username
|
# Account Username
|
||||||
|
|||||||
Reference in new issue
Block a user