SSH Execute Command on a Remote server

Via SSH you can connect to a remote server’s shell. This will allow you to execute commands on the external machine from your current one, managing a different server, not the one that you’re currently working on physically.

In order to execute SSH command on a remote server you need to do the following:

1. Have an external server set with Username and Password

2. Connect to the external server using

ssh user@server.hostname.com

– when prompted for the user’s password enter it

How to secure your remote SSH command execution?

Since this connection is available globally many other users around the Globe can connect to your server or initiate brute-force attacks, trying to login to your server while guessing the Username / Password. To protect from this, SSH also provides the option to establish a connection not directly using SSH Keys. You generate an SSH Key on the remote server and then enable it for authentication. Then you download it on your local machine and connect using it.

ssh -i /path/to/ssh_key user@server.hostname.com

– when prompted for the key’s password enter it

SSH Commands Options

The commands which you run through SSH and through a Linux machine’s terminal are usually Software written to directly interact with your machine. Those commands can do different actions and the way to dictate how this happens is to add flags and options to the commands.

For example the ls command lists all the content in the current working directory.

ls

Sample Output:
Downloads node_modules Public Templates
Desktop Recordings Videos Documents Music
Pictures sites ‘VirtualBox VMs’

One of the options for the ls command is to display everything as a list and to also show hidden (.dot) files as well, to achieve this we provide the following options to the ls command

ls -la # l - list, a - all

Sample Output:

drwx——. 9 root root 4096 Dec 10 11:57 .cache
drwxr-xr-x 17 root root 4096 Dec 10 11:57 .config
-rw-r–r–. 1 root root 100 Feb 12 2017 .cshrc
drwx—— 3 root root 4096 Jan 6 2018 .dbus
drwxr-xr-x 2 root root 4096 Dec 11 2017 Desktop
drwxr-xr-x 2 root root 4096 Dec 11 2017 Documents
drwxr-xr-x 2 root root 4096 Dec 11 2017 Downloads
-rw——- 1 root root 16 Dec 11 2017 .esd_auth
drwxr-xr-x 160 root root 4096 Dec 15 10:00 .esmtp_queue
drwx—— 3 root root 4096 Dec 11 2017 .gnupg
-rw——- 1 root root 620 Dec 10 11:56 .ICEauthority
drwxr-xr-x 3 root root 4096 Nov 13 2017 .local
drwxr-xr-x 2 root root 4096 Dec 11 2017 Music
-rw——- 1 root root 0 Nov 13 2017 .mysql_history
drwxr-xr-x 4 whf whf 4096 Feb 9 2018 .npm
drwxr-xr-x 2 root root 4096 Dec 11 2017 Pictures
drwxr—– 3 root root 4096 Nov 13 2017 .pki
drwxr-xr-x 2 root root 4096 Dec 11 2017 Public
drwx—— 2 root root 4096 Oct 15 20:23 .ssh
-rw-r–r–. 1 root root 129 Feb 12 2017 .tcshrc
drwxr-xr-x 2 root root 4096 Dec 11 2017 Templates
drwxr-xr-x 2 root root 4096 Dec 11 2017 Videos

There are many options to the commands which you can execute on your computer through its shell or on a remote machine via SSH. To view more information about the command you can consider its man page. This will provide information about the command, alternatively, you can also use –help in most cases

man ls
ls --help
  • 0 Kunder som kunne bruge dette svar
Hjalp dette svar dig?

Relaterede artikler

SSH ip command

If you wish to obtain information about your server’s IP on a Linux machine using SSH you can use...

SSH rm command

If you wish to remove a file or folder from your Linux system you can use SSH rm command. In this...

SSH echo command

One of the most useful commands in a Linux environment is echo. With it, you can provide output...

SSH history command

If you wish to find what commands you have previously executed in a Linux environment you can use...

SSH cd command

SSH cd command is mainly used to navigate in your Linux environment. In this article, we’ll show...

Powered by WHMCompleteSolution