🐧 Administración del sistema Linux
Linux es la columna vertebral de prácticamente todos los servidores, contenedores y entornos de nube. Esta referencia cubre comandos y patrones esenciales para la administración diaria del sistema en distribuciones Ubuntu/Debian y RHEL/Rocky.
Sistema de archivos y permisos
Los permisos de Linux se expresan como tres grupos (propietario, grupo, otros), cada uno con bits de lectura (r=4), escritura (w=2) y ejecución (x=1).
bash
chmod 755 /var/www/html # rwxr-xr-x (owner: rwx, group: rx, other: rx)
chmod 600 ~/.ssh/id_rsa # rw------- (private key — owner read/write only)
chmod -R 644 /var/www/html/*.html # Recursive set for files
chown -R www-data:www-data /var/www/html # Change owner and group
chown deploy:deploy /opt/app
# File listing with details
ls -lah /etc/nginx/ # Long format, human sizes, hidden files
ls -lt /var/log/ | head -20 # Sort by modification time
# Finding files
find /var/log -name "*.log" -mtime +30 -delete # Delete logs older than 30 days
find /opt/app -type f -name "*.conf" -exec grep -l "debug" {} \;
locate nginx.conf # Fast file lookup (requires updatedb)
# Disk usage
df -hT # Disk space by filesystem type
du -sh /var/log/* # Size of each log directory
ncdu / # Interactive disk usage explorerGestión de procesos
bash
ps aux # All processes (full detail)
ps aux | grep nginx # Filter by name
pgrep -a nginx # Process IDs matching name
htop # Interactive process manager (preferred)
# Signals
kill -15 1234 # SIGTERM — graceful shutdown
kill -9 1234 # SIGKILL — immediate kill (last resort)
killall nginx # Kill all processes named nginx
pkill -f "python worker.py" # Kill by pattern match
# Background jobs
nohup ./long-script.sh > /var/log/script.log 2>&1 & # Run detached
jobs -l # List background jobs
disown %1 # Detach job from terminal
# Priority
nice -n 10 ./batch-job.sh # Start with lower CPU priority
renice +5 -p 1234 # Change priority of running processRedes
bash
ip addr show # Show all interfaces
ip route show # Show routing table
ip link set eth0 up # Enable interface
# Connectivity
ping -c 4 8.8.8.8 # Test ICMP reachability
traceroute api.maxiscomputers.com # Trace network path
mtr --report api.maxiscomputers.com # Combined ping + traceroute
# DNS
dig api.maxiscomputers.com # DNS resolution (full detail)
dig +short api.maxiscomputers.com # Just the IPs
nslookup api.maxiscomputers.com # Legacy DNS tool
resolvectl status # systemd-resolved status
# Ports & Connections
ss -tulpn # All listening sockets with PID
ss -tnp state established # Active TCP connections
netstat -tulpn # Legacy equivalent
# Firewall (UFW — Ubuntu)
ufw status verbose
ufw allow 443/tcp
ufw allow from 10.0.0.0/8 to any port 22
ufw deny 23/tcp
# Firewall (firewalld — RHEL/Rocky)
firewall-cmd --list-all
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
# Traffic capture
tcpdump -i eth0 port 80 -w /tmp/capture.pcap
tcpdump -r /tmp/capture.pcap -nn "tcp"servicios del sistema
bash
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx # Reload config without downtime
systemctl status nginx # View status + recent logs
systemctl enable nginx # Auto-start on boot
systemctl disable nginx
systemctl is-active nginx
# Logs (journald)
journalctl -u nginx -f # Follow service logs
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx -p err # Errors only
journalctl --disk-usage
journalctl --vacuum-size=500M # Trim journal to 500MBini
[Unit]
Description=Maxi's Computers API Server
After=network-online.target postgresql.service
Wants=network-online.target
Requires=postgresql.service
[Service]
Type=simple
User=deploy
Group=deploy
WorkingDirectory=/opt/api-server
ExecStart=/usr/bin/node /opt/api-server/dist/index.js
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5s
StandardOutput=journal
StandardError=journal
SyslogIdentifier=api-server
LimitNOFILE=65536
NoNewPrivileges=yes
ProtectSystem=strict
PrivateTmp=true
[Install]
WantedBy=multi-user.targetEndurecimiento SSH
Deshabilitar la autenticación de contraseña Solo permita la autenticación basada en claves SSH en servidores de producción. La autenticación de contraseña es vulnerable a ataques de fuerza bruta.
bash
## Shell Scripting PatternsAjuste de rendimiento
bash
## Text Processing (grep, awk, sed)