How to access CentOS/Ubuntu Linux machine remotely? How to access CentOS/Ubun...

Step 1: Enable SSH on your machine

Linux has many distributions and you will need to enable SSH on your machine to access it remotely. Below are examples on how to enable SSH on some common Linux distributions such as Ubuntu 16.04 LTS, CentOS 7. SSH runs on port 22 by default.

Ubuntu 16
Install OpenSSH server: sudo apt-get install openssh-server
Check SSH service status: sudo service ssh status
Edit SSH config file: sudo vi /etc/ssh/sshd_config
Reload SSH:sudo service ssh restart


RHEL 7 Linux
Install OpenSSH server: yum install openssh
Check SSH service status: systemctl status sshd
Start SSH:systemctl start sshd
Edit SSH config file: sudo vi /etc/ssh/sshd_config
Reload SSH:systemctl restart sshd.service

Enable SSH in Linux

Step 2: Set up Port Forwarding (Port Translation) in the router

Please log into the router interface (generally at http://192.168.1.1 or http://192.168.0.1) and go into the 'Port Forwarding' section. Add a new 'Port Forwarding' rule for TCP port 22 to be forwarded to the internal IP of your Linux machine. The machine will be assigned an internal IP address even if you are running it as a Virtual Machine. To get the internal IP address, you may type ifconfig -i. It is usually in the form of "192.168.0.**".

Linux Check internal IP

NOTE: If you need to connect to several Linux machines behind the same router, you should set up port forwarding for all these machines. Let's suppose Linux machine 1 has an internal IP 192.168.0.24, machine 2 has an internal IP 192.168.0.46, and machine 3 has an internal IP 192.168.0.58. We can setup different external ports for different machines as shown in the picture below. You will need to change the SSH default port in the Linux machines as well by editing the config file located at /etc/ssh/sshd_config.

Port Forwarding for SSH Linux

To see if the port forwarding has been setup correctly, you can use our Port Check network tool to see if the corresponding port is open. If you get a "Success" response from the port check, then your network has been correctly set up.

STEP 4: Map your dynamic IP to a hostname

Internet service providers change your IP address on a regular basis, but with dynamic DNS you can keep your domain pointing at the current IP of your home server or other devices.

You may register a domain name of your own (yourdomain.com) and sign up for Dynu Dynamic DNS Service for it or use a free Dynu domain name (yourdomain.dynu.com). You may refer to this Getting started tutorial for more information.

STEP 5: Use Dynu DDNS service to access your machine remotely

Download our IP update client for Linux and run it on your machine to keep the hostname mapped to your dynamic IP. You may also set up the DDNS service in your router if your router supports it.

You should now be able to access your machine using yourhostname.dynu.com from outside the network via an SSH client such as Putty.exe.

Remote access Linux using Putty

NOTE: In the case of connecting several machines, for machine 1, you can use "yourhostname.dynu.com:22", for machine 2, you may use "yourhostname.dynu.com:23", and for machine 3, you may use "yourhostname.dynu.com:24".
Loading...