Pseudo-tty with ssh -t

The Secure Shell (SSH) protocol securely delivers instructions to a computer across an unsecured network. SSH is commonly used for remote server administration, infrastructure management, file transfer, and more.

🎧



The -t option in the ssh -t command forces pseudo-tty allocation.

This is especially useful when you need to execute remote screen-based apps on a distant server, providing something like a "temporary" SSH connection that exists while the command is running and closed as soon as the task is done.

Let's suppose we want to restart a remote server.

ssh -t snub@snubmonkey 'sudo shutdown -h now'

or

ssh -t snub@10.8.12 'sudo shutdown -h now'


The ssh session will terminate as soon as the given task is done; instead of log in to the particular remote server.

or

Let's quickly check which WIFI SSID we are connected to.

$ ssh -t snub@snubmonkey '/usr/local/bin/airport -I'                                                                                                           
(snub@snubmonkey) Password:
     agrCtlRSSI: -84
     agrExtRSSI: 0
    agrCtlNoise: -88
    agrExtNoise: 0
          state: running
        op mode: station 
     lastTxRate: 39
        maxRate: 144
lastAssocStatus: 0
    802.11 auth: open
      link auth: wpa2-psk
          BSSID: xx:xx:......
           SSID: free-wifi
            MCS: 4
        channel: 4
Connection to pipe closed.n -h now'

Et voila!