Created
April 26, 2024 22:52
-
-
Save karlosferreira/b714e7b8d9ca6acb4514d252eb23c9e5 to your computer and use it in GitHub Desktop.
Bash script for Initial server setup with ubuntu 20.04
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
#!/bin/bash | |
# Solicitar o nome do usuário | |
echo "Digite o nome do usuário:" | |
read novo_usuario | |
# Adicionar o usuário fornecido | |
adduser "$novo_usuario" | |
# Adicionar o usuário ao grupo sudo | |
usermod -aG sudo "$novo_usuario" | |
# Listar as aplicações permitidas pelo UFW | |
ufw app list | |
# Permitir conexões SSH | |
ufw allow OpenSSH | |
# Ativar o firewall UFW | |
ufw enable | |
# Verificar o status do firewall | |
ufw status | |
# Sincronizar as chaves SSH do usuário atual para o novo usuário | |
rsync --archive --chown="$novo_usuario:$novo_usuario" ~/.ssh "/home/$novo_usuario" | |
# Adicionar permissão sudo sem senha para o novo usuário | |
echo "$novo_usuario ALL=(ALL) NOPASSWD: ALL" | sudo EDITOR="tee -a" visudo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment