How To Run / Execute Command Using SSH

How To Run / Execute Command Using SSH

To run a command using SSH (Secure Shell), you will need to connect to a remote machine using the ssh command and then run the command on the remote machine.

Here is the basic syntax for connecting to a remote machine using the ssh command:

ssh user@host
Source‮:‬www.lautturi.com

The user argument is the username on the remote machine, and the host argument is the hostname or IP address of the remote machine.

For example, to connect to the remote machine example.com as the user user, you can use the following command:

ssh user@example.com

This will open an ssh session to the remote machine. Once you are connected, you can run commands on the remote machine as if you were logged in directly to the machine.

For example, to run the ls command to list the files in the current directory on the remote machine, you can use the following command:

ls

You can also specify a command to run on the remote machine as an argument to the ssh command.

For example:

ssh user@example.com 'ls -l'

This will run the ls -l command on the remote machine and display the output.

You can also use the -t option to force ssh to allocate a pseudo-tty, which is useful if you want to run interactive commands on the remote machine.

For example:

ssh -t user@example.com 'top'

This will run the top command on the remote machine, which displays information about the running processes on the system.

Created Time:2017-10-29 22:08:30  Author:lautturi