Scripts para administrar ssh, docker, samba, mysql, avahi, cups y mas
Last active
July 5, 2024 19:39
-
-
Save GermanMorini/220908f49a988f0afa729b7fa40c4a75 to your computer and use it in GitHub Desktop.
Scripts de bash para 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
#!/bin/bash | |
comm="Servidor apache2" | |
start() { | |
sudo systemctl enable --now httpd | |
status | |
} | |
start_online() { | |
sudo systemctl enable --now httpd && sudo ufw allow "Apache full" comment "$comm" | |
status | |
} | |
stop() { | |
sudo ufw delete allow "Apache full" | |
sudo systemctl disable --now httpd | |
status | |
} | |
restart() { sudo systemctl restart httpd; status; } | |
status() { systemctl status httpd; sudo ufw status numbered; } | |
config() { sudo nano /etc/httpd/conf/httpd.conf; } | |
case $* in | |
-S) start;; | |
-So) start_online;; | |
-s) stop;; | |
-rs) restart;; | |
-st) status;; | |
-l) journalctl -fu httpd;; | |
-c) config;; | |
-en) (systemctl enable httpd && echo "INFO: Servidor apache habilitado") || echo "ERR: ocurrió un error";; | |
-di) (systemctl disable httpd && echo "INFO: Servidor apache deshabilitado") || echo "ERR: ocurrió un error";; | |
*) echo "Opciones:" | |
echo " -S start" | |
echo " -So start online" | |
echo " -s stop" | |
echo " -rs restart" | |
echo " -st status" | |
echo " -l log" | |
echo " -c config" | |
echo " -en/-di habilitar/deshabilitar";; | |
esac |
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 | |
start() { | |
sudo systemctl enable --now avahi-daemon avahi-daemon.socket avahi-dnsconfd.service | |
status | |
} | |
stop() { | |
sudo systemctl disable --now avahi-daemon.socket; sleep 2; sudo systemctl disable --now avahi-daemon.service avahi-dnsconfd.service | |
status | |
} | |
status() { | |
systemctl status avahi-daemon avahi-daemon.socket avahi-dnsconfd.service | |
} | |
conf() { | |
sudo nano /etc/avahi/avahi-daemon.conf | |
} | |
case $* in | |
-s) stop;; | |
-S*) start;; | |
-st) status;; | |
-l) journalctl -fu avahi-daemon;; | |
-rs) stop; start;; | |
-c) conf;; | |
*) echo "Opciones:" | |
echo " -s detener" | |
echo " -S iniciar" | |
echo " -st estado" | |
echo " -l logs" | |
echo " -rs reiniciar" | |
echo " -c configuracion" | |
esac |
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 | |
start() { | |
# sudo systemctl enable --now cups.socket cups-lpd.socket cups.service cups.path | |
sudo systemctl enable --now cups.service | |
} | |
stop() { | |
# sudo systemctl disable --now cups.socket cups-lpd.socket; sleep 2; | |
sudo systemctl disable --now cups.service | |
} | |
reset() { | |
stop | |
start | |
status | |
} | |
status() { | |
# systemctl status cups.service cups.path cups.socket cups-lpd.socket | |
systemctl status cups.service cups.socket | |
} | |
case $* in | |
-S) start; status;; | |
-s) stop; status;; | |
-rs) reset;; | |
-st) status;; | |
*) echo "Opciones:" | |
echo " -S inicio" | |
echo " -s detener" | |
echo " -rs reiniciar" | |
echo " -st estado" | |
esac |
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 | |
start() { | |
sudo systemctl enable --now docker.service containerd.service | |
} | |
stop() { | |
sudo systemctl disable --now docker.socket; sleep 2; | |
sudo systemctl disable --now docker.service containerd.service | |
} | |
reset() { | |
stop | |
start | |
status | |
} | |
status() { | |
systemctl status docker.service containerd.service | |
} | |
case $* in | |
-S) start; status;; | |
-s) stop; status;; | |
-rs) reset;; | |
-st) status;; | |
*) echo "Opciones:" | |
echo " -S inicio" | |
echo " -s detener" | |
echo " -rs reiniciar" | |
echo " -st estado" | |
esac | |
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 | |
start() { | |
sudo systemctl enable --now mysql # mysqld mariadb.socket mariadb-extra.socket | |
} | |
stop() { | |
sudo ufw delete allow mysql | |
# sudo systemctl disable --now mariadb.socket mariadb-extra.socket; sleep 2; | |
sudo systemctl disable --now mysql | |
} | |
restart() { | |
sudo systemctl restart mysql # mysqld mariadb.socket mariadb-extra.socket | |
status | |
} | |
status() { | |
systemctl status mysql # mysqld mariadb.socket mariadb-extra.socket; | |
sudo ufw status numbered | |
} | |
case $* in | |
-S) start ;status;; | |
-So) start && sudo ufw allow mysql; status;; | |
-s) stop; status;; | |
-rs) restart;; | |
-st) status;; | |
-l) journalctl -fu mariadb;; | |
*) echo "Opciones:" | |
echo " -S Iniciar" | |
echo " -So Iniciar online" | |
echo " -s Acabar" | |
echo " -rs Reiniciar" | |
echo " -st Estado" | |
echo " -l Registros" | |
esac |
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 | |
status() { | |
systemctl status $1 | head -n1 | cut -d' ' -f1,2 | cut -d'.' -f1 | |
} | |
case $* in | |
'') | |
status avahi-daemon | |
status containerd | |
status cups | |
status docker | |
status httpd | |
status mysql | |
status smb | |
status sshd | |
status sshguard | |
;; | |
*) | |
echo "Opciones:" | |
echo " <vacío> listar servicios" | |
echo " -h ayuda" | |
;; | |
esac |
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 | |
comm="Samba de mi esperanza" | |
start() { | |
sudo ufw allow samba comment "$comm" && sudo systemctl enable --now smb | |
status | |
} | |
stop() { | |
sudo ufw delete allow samba | |
sudo systemctl disable --now smb | |
status | |
} | |
reset() { | |
sudo systemctl restart smb | |
status | |
} | |
config() { sudo nano /etc/samba/smb.conf; } | |
status() { systemctl status smb; sudo ufw status numbered; } | |
case $* in | |
-S) start;; | |
-s) stop;; | |
-rs) reset;; | |
-c) config;; | |
-l) journalctl -fu smb;; | |
-st) status;; | |
*) echo "Opciones:" | |
echo " -S start" | |
echo " -s stop" | |
echo " -rs reset" | |
echo " -c config" | |
echo " -l log" | |
echo " -st status" | |
esac |
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 | |
comm="Servidor SSH" | |
fingerp="$(hostname).local $(cat /etc/ssh/ssh_host_ed25519_key.pub | cut -d' ' -f1,2)" | |
function start() { | |
sudo ufw allow OpenSSH comment "$comm" && sudo systemctl enable --now sshd && sudo systemctl enable --now sshguard | |
status | |
} | |
function restart() { | |
sudo systemctl restart sshd | |
status | |
} | |
function config() { | |
sudo nano /etc/ssh/sshd_config | |
} | |
function userConfig() { | |
sudo nano /etc/ssh/ssh_config | |
} | |
function stop() { | |
sudo ufw delete allow OpenSSH | |
sudo systemctl disable --now sshd | |
sudo systemctl disable --now sshguard | |
status | |
} | |
function status() { systemctl status sshd; systemctl status sshguard; sudo ufw status numbered; } | |
function genKeys() { | |
if [ -d "/home/$1" ]; then | |
local check=0 | |
local dname="$1-keys" | |
local kname="$(hostname)_ed25519" | |
mkdir "$dname"; | |
echo "$fingerp" >> "./$dname/known_hosts" | |
ssh-keygen -t ed25519 -f "./$dname/$kname" -P "" -C "$1@$(hostname)"; check=$((check + $?)) | |
cat "./$dname/$kname.pub" >> "/home/$1/.ssh/authorized_keys"; check=$((check + $?)) | |
zip -r "./$dname.zip" "./$dname"; check=$((check + $?)) | |
rm -r "./$dname" | |
exit $check | |
else | |
echo "El usuario $1 no existe!" | |
exit 1 | |
fi | |
} | |
function retKeys() { | |
if [ -d "/home/$1" ]; then | |
local check=0 | |
local dname="$1-keys" | |
local kname="/home/$1/.ssh/id_ed25519" | |
mkdir "$dname" | |
echo "$fingerp" >> "./$dname/known_hosts" | |
cp -a "$kname" "$dname/${kname##*/}"; check=$((check + $?)) | |
cp -a "$kname.pub" "$dname/${kname##*/}.pub"; check=$((check + $?)) | |
zip -r "$dname.zip" "$dname"; check=$((check + $?)) | |
rm -r "$dname" | |
else | |
echo "El usuario $1 no existe!" | |
exit 1 | |
fi | |
} | |
case $* in | |
-S) start;; | |
-s) stop;; | |
-rs) restart;; | |
-st) status;; | |
-l) journalctl -fu sshd;; | |
-gl) journalctl -fu sshguard;; | |
-c) config;; | |
-uc) userConfig;; | |
-gk*) genKeys "$2";; | |
-rk*) retKeys "$2";; | |
-fp) ssh-keygen -l -E sha256 -f "/etc/ssh/ssh_host_ed25519_key.pub";; | |
*) echo "Opciones:" | |
echo " -S start" | |
echo " -s stop" | |
echo " -rs restart" | |
echo " -st status" | |
echo " -l log" | |
echo " -gl SSHGuard log" | |
echo " -c Configuración del servidor" | |
echo " -uc ... de los usuarios" | |
echo " -gk <user> generar claves" | |
echo " -rk <user> obtener claves" | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment