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:
- Connect to the remote machine using the following syntax:
ssh user@remote-hostReplace "user" with your username on the remote machine and "remote-host" with the hostname or IP address of the remote machine.
- Once you are connected, you can run multiple commands by chaining them together with semicolons (;). For example:
command1; command2; command3- To safely exit the SSH session, use the following command:
exitAlternatively, 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.
