master df282c19f2e7 cached
3 files
2.5 KB
736 tokens
1 requests
Download .txt
Repository: do-community/automated-setups
Branch: master
Commit: df282c19f2e7
Files: 3
Total size: 2.5 KB

Directory structure:
gitextract_zipa43sp/

├── README.md
└── Ubuntu-18.04/
    ├── README.md
    └── initial_server_setup.sh

================================================
FILE CONTENTS
================================================

================================================
FILE: README.md
================================================
# Automated Setups


================================================
FILE: Ubuntu-18.04/README.md
================================================
# Scripts

## initial_server_setup.sh

* [Automation tutorial](https://www.digitalocean.com/community/tutorials/automating-initial-server-setup-with-ubuntu-18-04)
* [Manual process](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04)


================================================
FILE: Ubuntu-18.04/initial_server_setup.sh
================================================
#!/bin/bash
set -euo pipefail

########################
### SCRIPT VARIABLES ###
########################

# Name of the user to create and grant sudo privileges
USERNAME=sammy

# Whether to copy over the root user's `authorized_keys` file to the new sudo
# user.
COPY_AUTHORIZED_KEYS_FROM_ROOT=true

# Additional public keys to add to the new sudo user
# OTHER_PUBLIC_KEYS_TO_ADD=(
#     "ssh-rsa AAAAB..."
#     "ssh-rsa AAAAB..."
# )
OTHER_PUBLIC_KEYS_TO_ADD=(
)

####################
### SCRIPT LOGIC ###
####################

# Add sudo user and grant privileges
useradd --create-home --shell "/bin/bash" --groups sudo "${USERNAME}"

# Check whether the root account has a real password set
encrypted_root_pw="$(grep root /etc/shadow | cut --delimiter=: --fields=2)"

if [ "${encrypted_root_pw}" != "*" ]; then
    # Transfer auto-generated root password to user if present
    # and lock the root account to password-based access
    echo "${USERNAME}:${encrypted_root_pw}" | chpasswd --encrypted
    passwd --lock root
else
    # Delete invalid password for user if using keys so that a new password
    # can be set without providing a previous value
    passwd --delete "${USERNAME}"
fi

# Expire the sudo user's password immediately to force a change
chage --lastday 0 "${USERNAME}"

# Create SSH directory for sudo user
home_directory="$(eval echo ~${USERNAME})"
mkdir --parents "${home_directory}/.ssh"

# Copy `authorized_keys` file from root if requested
if [ "${COPY_AUTHORIZED_KEYS_FROM_ROOT}" = true ]; then
    cp /root/.ssh/authorized_keys "${home_directory}/.ssh"
fi

# Add additional provided public keys
for pub_key in "${OTHER_PUBLIC_KEYS_TO_ADD[@]}"; do
    echo "${pub_key}" >> "${home_directory}/.ssh/authorized_keys"
done

# Adjust SSH configuration ownership and permissions
chmod 0700 "${home_directory}/.ssh"
chmod 0600 "${home_directory}/.ssh/authorized_keys"
chown --recursive "${USERNAME}":"${USERNAME}" "${home_directory}/.ssh"

# Disable root SSH login with password
sed --in-place 's/^PermitRootLogin.*/PermitRootLogin prohibit-password/g' /etc/ssh/sshd_config
if sshd -t -q; then
    systemctl restart sshd
fi

# Add exception for SSH and then enable UFW firewall
ufw allow OpenSSH
ufw --force enable
Download .txt
gitextract_zipa43sp/

├── README.md
└── Ubuntu-18.04/
    ├── README.md
    └── initial_server_setup.sh
Condensed preview — 3 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (3K chars).
[
  {
    "path": "README.md",
    "chars": 19,
    "preview": "# Automated Setups\n"
  },
  {
    "path": "Ubuntu-18.04/README.md",
    "chars": 271,
    "preview": "# Scripts\n\n## initial_server_setup.sh\n\n* [Automation tutorial](https://www.digitalocean.com/community/tutorials/automati"
  },
  {
    "path": "Ubuntu-18.04/initial_server_setup.sh",
    "chars": 2238,
    "preview": "#!/bin/bash\nset -euo pipefail\n\n########################\n### SCRIPT VARIABLES ###\n########################\n\n# Name of the"
  }
]

About this extraction

This page contains the full source code of the do-community/automated-setups GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 3 files (2.5 KB), approximately 736 tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!