A quick server check often takes a single shell command. OpenSSH can run that command on the remote host and show its output in your local terminal without opening an interactive shell.
Your remote account's permissions govern what the command can read or change. The server uses that account's shell and environment to interpret the command text.
You need the OpenSSH client, a local shell such as Bash or Zsh, and an account with SSH access to the server. If SSH prompts you to trust a host key, accepting an unverified key can send your command to an impostor. Answer yes only if the displayed fingerprint matches one you obtained through a trusted channel, such as directly from your server administrator. If the fingerprints differ or you have no trusted fingerprint, answer no and stop.
Steps to run a remote command over SSH:
- Run a command on the remote host with ssh.
$ ssh user@host \ 'ls -d "$HOME"' /home/user
user and host stand for your remote login and server address. The text inside the outer single quotes is the command you replace. The directory lookup uses ls and assumes a POSIX shell on the remote host, as on Linux and macOS servers. The outer single quotes leave $HOME for the remote shell to expand. The inner double quotes keep a path with spaces in one argument.
- Check the SSH exit status immediately in the same local shell.
$ echo "$?" 0
$? holds the most recent command's status. A status of 0 means the remote command succeeded. When the remote command fails, ssh returns its nonzero status. An SSH error such as a refused connection returns 255. The SSH error message matters if the remote command can return 255 too.