How To Run Multiple SSH Command On Remote Machine And Exit Safely

To run multiple SSH commands on a remote machine and exit safely, you can use the following method:

  1. Connect to the remote machine using the following syntax:
ssh user@remote-host

Replace “user” with your username on the remote machine and “remote-host” with the hostname or IP address of the remote machine.

  1. Once you are connected, you can run multiple commands by chaining them together with semicolons (;). For example:
command1; command2; command3
  1. To safely exit the SSH session, use the following command:
exit

Alternatively, you can also use the following syntax to run multiple SSH commands in one line without having to interact with the remote machine:

ssh user@remote-host 'command1; command2; command3'

This way, the commands will be executed on the remote machine, and the SSH session will automatically exit after the commands have completed.

Leave a Comment