Servers and cloud

Run a command or script on a server over SSH

Run something on a remote server without logging in first, even a script from your own machine.

Fill these in once
  1. Run one command on the server
    Terminal
    ssh ubuntu@203.0.113.10 'df -h'
  2. Run a script from your machine on the server
    Terminal
    ssh ubuntu@203.0.113.10 'bash -s' < setup.sh
  1. Run one command on the server
    Terminal · Ubuntu / Debian
    ssh ubuntu@203.0.113.10 'df -h'
  2. Run a script from your machine on the server
    Terminal · Ubuntu / Debian
    ssh ubuntu@203.0.113.10 'bash -s' < setup.sh
  1. Run one command on the server
    PowerShell
    ssh ubuntu@203.0.113.10 'df -h'
  2. Run a script from your machine on the server
    PowerShell
    Get-Content setup.sh | ssh ubuntu@203.0.113.10 'bash -s'

    Save the script with Unix line endings (LF), or bash on the server will complain.