aboutsummaryrefslogtreecommitdiff
path: root/lib/40-user
diff options
context:
space:
mode:
authorCullum Smith <cullum@sacredheartsc.com>2024-07-12 15:20:54 -0400
committerCullum Smith <cullum@sacredheartsc.com>2024-07-12 15:20:54 -0400
commit241833b7f320e7fca84ba226f1ecbb0c963534f7 (patch)
treeee9839af8bee6ec9c5cac08306e3167634babcec /lib/40-user
parent8ec6df0afeb4ef69fa64de5516d16f4be48e0549 (diff)
downloadinfrastructure-241833b7f320e7fca84ba226f1ecbb0c963534f7.tar.gz
initial commit of hypervisor configs
Diffstat (limited to 'lib/40-user')
-rw-r--r--lib/40-user26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/40-user b/lib/40-user
new file mode 100644
index 0000000..42bbb82
--- /dev/null
+++ b/lib/40-user
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set_authorized_keys(){
+ # Add authorized_keys for a user.
+ # $1 = username
+ # $2 = newline-separated string of authorized keys
+ _sak_homedir=$(eval echo "~${1}")
+ _sak_group=$(getent passwd "$1" | awk -F: '{ print $4}')
+
+ # Create authorized keys file and set permissions.
+ install_directory -o "$1" -g "$_sak_group" -m 0700 "${_sak_homedir}/.ssh"
+ [ -f "${_sak_homedir}/.ssh/authorized_keys" ] || touch "${_sak_homedir}/.ssh/authorized_keys"
+ chown "$1" "${_sak_homedir}/.ssh/authorized_keys"
+ chgrp "$_sak_group" "${_sak_homedir}/.ssh/authorized_keys"
+ chmod 600 "${_sak_homedir}/.ssh/authorized_keys"
+
+ printf '%s\n' "${2}" > "${_sak_homedir}/.ssh/authorized_keys"
+ log "added authorized_keys for ${1}:"$'\n'"$2"
+}
+
+set_password(){
+ # Set password for a local user.
+ # $1 = username
+ # $2 = password
+ printf '%s\n%s\n' "$2" "$2" | passwd "$1" > /dev/null
+}