--- name: no-sudo-server-setup description: Deploy redis, venv, systemd workarounds when lacking sudo. tags: [deployment, sudo, redis, venv, workaround] triggers: - "no sudo" - "cannot sudo" - "deploy without root" - "无sudo" --- # No-Sudo Server Setup Patterns When deploying on a server where you have a user account but no sudo/root access. ## Redis from Source (no `apt install`) ```bash curl -sLO https://download.redis.io/releases/redis-7.2.5.tar.gz tar xzf redis-7.2.5.tar.gz && cd redis-7.2.5 make -j$(nproc) cp src/redis-server src/redis-cli ~/bin/ ~/bin/redis-server --daemonize yes --port 6379 --logfile ~/logs/redis.log ``` ## Python venv without `python3-venv` (Debian/Ubuntu) ```bash pip3 install --user virtualenv python3 -m virtualenv /path/to/venv ``` ## pip Mirror (China) ```bash mkdir -p ~/.pip cat > ~/.pip/pip.conf << 'EOF' [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn EOF ``` ## Hostname Without `/etc/hosts` When scripts reference `mysql -h db` but `db` doesn't resolve: - Change config connection host from `db` to `127.0.0.1` - Or get someone with sudo to `echo '127.0.0.1 db' >> /etc/hosts` ## systemd Without sudo - Use `start.sh`/`stop.sh` scripts instead of systemd - Auto-restart: `@reboot bash /path/to/start.sh` in crontab - Crash watchdog: `*/1 * * * * pgrep -f app.py || bash start.sh` ## xls2ddl Warning Filtering xls2ddl outputs openpyxl warnings mixed with SQL — filter before piping to mysql: ```bash xls2ddl mysql models/ > /tmp/ddl.sql grep -v 'UserWarning\|warn(msg)\|openpyxl' /tmp/ddl.sql | mysql -u user -ppass -h 127.0.0.1 db ``` ## Dummy Env Vars for Optional Services ```bash export BAIDU_SMS_ACCESS_KEY=dummy export BAIDU_SMS_ACCESS_KEY_SECRET=dummy export BAIDU_SMS_HOST=dummy export BAIDU_SMS_SIGNATURE_ID=dummy ``` ## bricks First Build ```bash mkdir -p pkgs/bricks/dist/{css,i18n,imgs,3parties,examples,docs} cd pkgs/bricks/bricks && bash build.sh ln -sf ../pkgs/bricks/dist wwwroot/bricks ``` ## MariaDB localhost Auth MariaDB uses `unix_socket` for `user@localhost`. Creating `user@'%'` isn't enough: ```sql CREATE USER 'test'@'localhost' IDENTIFIED BY 'test123'; CREATE USER 'test'@'127.0.0.1' IDENTIFIED BY 'test123'; GRANT ALL ON db.* TO 'test'@'localhost'; GRANT ALL ON db.* TO 'test'@'127.0.0.1'; ``` ## DB Password AES Encryption (Sage/ahserver) ```python from appPublic.aes import aes_encode_b64 enc = aes_encode_b64(password_key, plaintext_password) ``` ## SSH Rate Limiting Symptom: first SSH works, subsequent calls fail `kex_exchange_identification`. Fix: `sleep 12` between calls, or batch into one command. ## Pitfall: SSH 255 from Background Commands `ssh host "cmd1 && cmd2 &"` returns exit 255 — the `&` or `pkill` kills SSH's own shell. Split into single-purpose calls, never use shell background `&` in SSH commands.