Use WP-CLI remotely over SSH on web host Strato

Strato half-secretly has decent SSH access even for its cheap plans, but it comes with quirks. To use WP-CLI comfortably,  I jumped through these hoops:

  1. I recommend we set up key-based, password-less login
    ssh-copy-id yourdomain.com@ssh.strato.de
    # or
    ssh yourdomain.com@ssh.strato.de
    mkdir -m 700 ~/.ssh
    touch ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
    vim ~/.ssh/authorized_keys # paste your ~/.ssh/id_rsa.pub here
  2. I recommend we create an SSH alias
    # local ~/.ssh/config
    Host strato
    Hostname ssh.strato.de
    User yourdomain.com
    ServerAliveInterval 30
  3. Install remote wp-cli (make sure we have it locally, too)
    ssh strato
    mkdir bin && cd bin
    # check wp-cli.org for up-to-date command!!
    #curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  4. Create the “wp” alias on the remote machine
    Find php-cli
    /usr/bin/php -v
    # PHP 7.2.17 (cgi-fcgi) # wrong!
    /opt/RZphp72/bin/php-cli -v
    # PHP 7.2.17 (cli) # here we go!

    Check the remote’s default shell & $HOME
    echo $SHELL
    # /bin/tcsh in my case!
    echo $HOME
    # /mnt/webr/01/23/456789ab/htdocs

    Set up the alias
    #.tcshrc
    alias wp /opt/RZphp72/bin/php-cli /mnt/webr/01/23/456789ab/htdocs/bin/wp-cli.phar
    set path = ($path /usr/local/bin $HOME/bin .) # can be handy!
    #.bashrc
    alias wp='/opt/RZphp72/bin/php-cli /mnt/webr/01/23/456789ab/htdocs/bin/wp-cli.phar'
    PATH=${PATH}:${HOME}/bin # can be handy!
  5. I recommend we set up a local WP-CLI alias:
    #~/.wp-cli/config.yml
    @strato
    ssh: strato/mnt/webr/01/23/456789ab/htdocs/path-to-your-wp
  6. Test!
    wp @strato
    wp @strato --info
    wp @strato post list
    # go back? debug?
    wp --ssh=strato/mnt/…
    wp --ssh=yourdomain.com@ssh.strato.de/mnt/…
    ssh strato wp
    ssh strato /opt/RZphp72/bin/php-cli /mnt/webr/01/23/456789ab/htdocs/bin/wp-cli.phar
    #etc.