Last active
October 17, 2021 12:34
-
-
Save vincejv/4ae1404bbc62ab9c6a706bb01302429f to your computer and use it in GitHub Desktop.
Create daemon user in linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ------ | |
# Creates a daemon user in linux | |
# usage: create-daemon-usr.sh <username> | |
# ------ | |
# Add user | |
/usr/sbin/useradd -r $1 | |
# Remove shell | |
/usr/sbin/usermod --shell /sbin/nologin "$1" | |
# Create Daemon home directory | |
mkdir -p "/var/lib/$1" | |
# Move user home directory to /var/lib/{username} | |
/usr/sbin/usermod -d "/var/lib/$1" "$1" | |
# Make daemon user owner for their files in their home directory | |
chown -R "$1:$1" "/var/lib/$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ------ | |
# Prepares home directory of daemon user in linux | |
# making symlinks of rc files from /opt directory | |
# $1 = HOME DIR | |
# $2 = USERNAME | |
# usage: prepare-daemon-env.sh <home_dir> <username> | |
# ------ | |
DAEMON_USER="$2" | |
DAEMON_HOME="$1/" | |
SAMBA_PWD_EXT=".smbpasswd" | |
OPT_DIR=/opt | |
# Make symlink to mutt and msmtp | |
ln -s /opt/.muttrc "$DAEMON_HOME/" | |
ln -s /opt/.msmtprc "$DAEMON_HOME/" | |
# msmtpq directories | |
mkdir -p "$DAEMON_HOME/.msmtp.queue" | |
mkdir -p "$DAEMON_HOME/.msmtp" | |
# aria2 directories and files | |
atouch ".cache/aria2/dht.dat" | |
atouch ".cache/aria2/dht6.dat" | |
touch "aria2.session" | |
# Make symlink to samba password for autofs | |
for FILE in "$OPT_DIR/*$SAMBA_PWD_EXT"; do ln -s "$FILE" "$DAEMON_HOME"; done | |
# Make daemon user owner for their files in their home directory | |
chown -R "$DAEMON_USER:$DAEMON_USER" "$DAEMON_HOME/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# --- | |
# Test daemon user privileges | |
# usage: run-as.sh <username> "<command>" | |
# --- | |
$BASH_USER="$1" | |
$COMMAND="$2" | |
# sudo -u transmission bash -c 'echo "$HOME"' | |
sudo -u "$BASH_USER" bash -c "'$COMMAND'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment