To run a command using SSH on a remote server, follow these steps:
- Open a terminal or command prompt on your local machine.
- Type the following command:
ssh username command
Replace
usernamewith your username on the remote server,remote_hostwith the hostname or IP address of the remote server, andcommandwith the command you want to run.For example, if you want to run the
lscommand on the remote server, you would type:ssh username ls
- If this is the first time you are connecting to the remote server, SSH will prompt you to add the remote server’s fingerprint to your local machine’s known_hosts file. Follow the prompts to add the fingerprint.
- SSH will then prompt you for your password on the remote server. Enter your password and press Enter.
Note: If you have set up public key authentication, you will not need to enter a password.
- The command you specified will then be executed on the remote server, and the output will be displayed in your local terminal or command prompt.
Once you have completed these steps, you should be able to run commands on the remote server using SSH from your local machine.