Skip to content

Instantly share code, notes, and snippets.

@mikepage
Last active July 2, 2025 10:44
Show Gist options
  • Save mikepage/8bee126dfc7822b1fe35b9822a5b6dd5 to your computer and use it in GitHub Desktop.
Save mikepage/8bee126dfc7822b1fe35b9822a5b6dd5 to your computer and use it in GitHub Desktop.

Directadmin, add default ssh keys for new users

Create the custom scripts directory (if it doesn’t exist)

mkdir -p /usr/local/directadmin/scripts/custom

Create the user_create_post.sh script or update existing script when immunify360 is active

vi /usr/local/directadmin/scripts/custom/user_create_post.sh

#!/bin/sh
/usr/bin/imunify360-agent add-sudouser --user "$username"

# SSH key sync
USERNAME=$username
USER_HOME="/home/${USERNAME}"
SSH_DIR="${USER_HOME}/.ssh"
AUTHORIZED_KEYS="${SSH_DIR}/authorized_keys"

# Create .ssh directory
mkdir -p "${SSH_DIR}"
chmod 700 "${SSH_DIR}"
chown ${USERNAME}:${USERNAME} "${SSH_DIR}"

# Add your public key
cat /root/default_ssh_keys.pub > "${AUTHORIZED_KEYS}"
chmod 600 "${AUTHORIZED_KEYS}"
chown ${USERNAME}:${USERNAME} "${AUTHORIZED_KEYS}"

Update permissions

chmod +x /usr/local/directadmin/scripts/custom/user_create_post.sh

Update default ssh keys file

vi /root/default_ssh_keys.pub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment