run commands on a server over ssh

Run one command or a whole local script on another machine, without logging in by hand.

  • network

Steps

  1. ssh NAME@host 'uptime'

    one command; its output comes back here

  2. ssh NAME@host 'cd /app && git pull && sudo systemctl restart app'

    several, in order

  3. ssh NAME@host 'bash -s' < local-script.sh

    run a script from this machine there

  4. ssh -t NAME@host 'sudo systemctl restart app'

    one that asks for a password (-t gives it a terminal)

  5. ssh NAME@host 'cat /var/log/app.log' > app.log

    bring a file's text back

Commands used

  • ssh

Each has a page in lore: lore ssh opens it.