This comprehensive Linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has
sudo
access and that you precede each of the privileged commands withsudo
There are many ways to establish a connection with a remote machine depending on the operating system you are running, but the two most used protocols are:
- Secure Shell (SSH) for Linux-based machines
- Remote Desktop Protocol (RDP) for Windows-based machines
Secure Shell (SSH) is a commonly used protocol to gain remote access through a command line interface. Administrators with advanced knowledge may use SSH to log in to a web server and perform tasks such as file and folder transfers, disk usage reviews and performance monitoring, using commands such as top).
Linux
To connect to a SSH server on your linux, you first need to install OpenSSH Client on your system.
Installing OpenSSH Client
Run the following command to install the OpenSSH client on your linux:
root@codesposts:~$ apt-get install openssh-client
Installing OpenSSH Server
Run the following command to install the OpenSSH server on your linux:
root@codesposts:~$ apt-get install openssh-server ii.
Verifying Installation Of OpenSSH Client
You can type the following command to verify the installation of OpenSSH Client on your system. If the OpenSSH Client is installed on your system, the output will look like this:
root@codesposts:~$ ssh
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]
Verifying Installation Of OpenSSH Server
You can type the following command to verify the installation of OpenSSH Server on your system. If the OpenSSH Server is installed on your system, the output will look like this:
root@codesposts:-$ service ssh status
• ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
Active: active (running) since Fr 2018-03-12 10:53:44 CET; 1min 22s ago Process: 1174 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCES
Main PID: 3165 (sshd)
General Syntax
Following is the general syntax of the OpenSSH
root@codesposts:~$ ssh [username]@[hostname]
Example
root@codesposts:~$ ssh [email protected]
[email protected]'s password:
The authenticity of host '149.28.57.113 (149.28.57.113)' can't be established. ECDSA key fingerprint is SHA256:9lyrpzo5Yo1EQAS2QeHy9xKceHFH8F8W6kp7EX2O3Ps. Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ' 149.28.57.113' (ECDSA) to the list of known hosts.
[email protected]:~$
You’ll see a message asking you to confirm the identity of the server the first time you connect. If this is actually the first time you connected to the server, this is normal and you can type “yes” to continue.
VNC Over SSH
For users who are used to working in a graphical desktop environment with Virtual Network Computing (VNC), it is possible to completely encrypt connections using SSH tunneling. In order to tunnel VNC connections over SSH, you will need to run this command in the terminal on your Linux or UNIX machine:
root@codesposts:~$ ssh -L 5901:localhost:5901 -N -f -l username hostname_or_IP
Windows
The Windows Command Prompt application does not support SSH by default. We recommend downloading a third-party application such as PuTTY, which includes SSH support.
Download & Install PuTTY
Click Here to download PuTTy and then install it on your windows.
After successful installation of PuTTY, open PuTTY desktop application.
Enter your server connection settings:
- Host Name: example.com OR 149.28.57.100 (change it to the IP of your server)
- Port: 22 (leave as default)
- Connection Type: SSH (leave as default)
You’ll see a security alert the first time you try to connect to a server. This tells you that you haven’t previously connected to this server. That’s expected, so click “YES” to continue.
You’ll be prompted to enter the username and password for your account on the SSH server. After you do, you’ll be connected. Just close the window to end the SSH connection.
Mac
The procedure to connect to a server through SSH in mac is same as in linux.
Open the terminal and run the following command:
root@codesposts:~$ ssh [username]@[hostname]
Change the [username] to your username and [hostname] to the name of the host or the IP of the host.
Last login: Mon July 22 20:27:32 on ttys000
Codesposts-Macbook-Air:~ root$ ssh [email protected]
You’ll be asked if you wish to continue connecting. Enter yes. Then you will be prompted for your password. Enter the password and you will be connected to your server.