run commands on a server over ssh
Run one command or a whole local script on another machine, without logging in by hand.
Steps
-
ssh NAME@host 'uptime'one command; its output comes back here
-
ssh NAME@host 'cd /app && git pull && sudo systemctl restart app'several, in order
-
ssh NAME@host 'bash -s' < local-script.shrun a script from this machine there
-
ssh -t NAME@host 'sudo systemctl restart app'one that asks for a password (-t gives it a terminal)
-
ssh NAME@host 'cat /var/log/app.log' > app.logbring a file's text back
Commands used
ssh
Each has a page in lore: lore ssh opens it.
Related recipes
- check a certificateSee a site's TLS certificate, when it expires and who issued it, or the same for a .pem file.
- copy files to and from a serverCopy a file or a whole folder between this machine and another one over ssh.
- download a whole folder from a websiteFetch every file under a web folder, without climbing to the folders above it.
- find this machine's ip addressThis machine's address on the local network, and the one the internet sees.