How to use SSH command in Linux to connect to remote server with examples

Secure Shell (SSH) is a protocol for securely accessing a remote computer. SSH is a package consisting of three utilities – slogin, ssh, and scp. SSH sends commands which are encrypted and thus secure.Once connected client server connection is authenticated using digital certificate and encrypted password.

Syntax

ssh remote_host

where remote_host is host name or host ip address

Example

ssh 10.17.2.45

ssh mylinux.com

This command will work only if remote username is same as local username. Once connected remote system will authenticate user by asking for password.

In case username for remote system is different use below command

Syntax

ssh user_name@remote_host

When logging in for first time you will get message “host key not found”. Simply type yes to continue further. The host key will be stored locally, in .ssh/hostkey folder of your home folder. Next time when you login it will only ask for login password as hostkey is already stored.

Copy files over ssh using scp

ssh can be used to copy files local system to remote server as well as from remote server to local system.

Copy files from remote server to localhost

scp username@Remote_Host_server:/Path/To/Remote/Directory /local_path/

Copy files from local host to remote server

scp file_name username@Remote_Host_server:/Path/To/Remote/Directory