You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
986 B
39 lines
986 B
#!/bin/bash
|
|
|
|
# Ensure the script is run as root
|
|
if [ "$(id -u)" != "0" ]; then
|
|
echo "This script must be run as root" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
# Update and Upgrade the System
|
|
apt update && apt upgrade -y
|
|
|
|
# Install sudo and other necessary packages
|
|
apt install -y sudo openssh-server
|
|
|
|
# Create the ansible user
|
|
useradd -m -s /bin/bash ansible
|
|
|
|
# Set up SSH for the ansible user
|
|
mkdir -p /home/ansible/.ssh
|
|
chmod 700 /home/ansible/.ssh
|
|
touch /home/ansible/.ssh/authorized_keys
|
|
chmod 600 /home/ansible/.ssh/authorized_keys
|
|
|
|
# Replace 'your_public_key' with the actual public key
|
|
echo 'your_public_key' > /home/ansible/.ssh/authorized_keys
|
|
|
|
# Change ownership of the .ssh directory to the ansible user
|
|
chown -R ansible:ansible /home/ansible/.ssh
|
|
|
|
# Configure sudo privileges
|
|
echo 'ansible ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/ansible
|
|
|
|
# Ensure the sudoers file is secure
|
|
chmod 0440 /etc/sudoers.d/ansible
|
|
|
|
# Install Ansible
|
|
apt install -y ansible
|
|
|
|
echo "Ansible and user setup complete."
|