Connecting to the container using SSH
  • 2 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Connecting to the container using SSH

  • Dark
    Light
  • PDF

Container access with ssh

DNIF container can be accessed using SSH on a custom ssh (tcp/826) port from the host machine.

Login to DNIF container

  • Open a terminal window on your host machine and enter the following command.
$ ssh root@localhost -p 826
  • Enter the password tSV67BZ7bJKnme4
Note

A new bash prompt will open up signifying that you have access to the container.

Understanding the connection between the host machine and the docker container

  • Docker container uses port 826 of the host machine. The host machine in turn connects over default SSH port 22 with the docker container via ssh port 826.

image.png

The recommended method to connect to your docker container is:

  • Connect to the host machine via ssh port 22.
  • Connect to the container via the host machine to ssh port 826 (check diagram above)

Change the login password of the DNIF container

  • Change your DNIF container password using the following command,
$ passwd root

The output for the above command will be displayed as follows:

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Note

The changed password will be effective only till the container is reset/restarted. After restart the container login password shall change back to the default password tSV67BZ7bJKnme4 as per the original configuration.

Note
  • The Docker container SSH port cannot be changed as port 826 is exposed during the compilation of the container.
  • If the SSH port is changed from the sshd_config file, the port shall change but the user will be unable to login, as the port is unexposed.

Securing DNIF container

image.png

image.png

  • For a secured connection it is recommended to set UFW ( Unix Firewall ) rules to only allow authorized IP addresses to connect to Docker port 826 on the host machine. This rule shall deny unauthorized access to the Docker.

  • Execute the following command to allow authorized IP addresses to connect to Docker port 826 on the host machine.

$ ufw default allow incoming

The output for the above command will be displayed as follows:

Default incoming policy changed to 'allow'
(be sure to update your rules accordingly)
  • Execute the following command to deny unauthorized access to Docker port 826 on the host machine.
$ ufw deny in on eth0 to any port 826 proto tcp

The output for the above command will be displayed as follows:

Rules updated
Rules updated (v6)
Note: Where 'eth0' is the name of your NIC card.
  • Execute the following command to allow SSH incoming connections
$ ufw enable

The output for the above command will be displayed as follows:

Output:

Command may disrupt existing ssh connections. Proceed with operation (y|n)? Y
Firewall is active and enabled on system startup
$ ufw status

The output for the above command will be displayed as follows:

Output:

Status: active

To                     Action     From
--                     ------     ----
826/tcp on enp0s3      DENY       Anywhere
826/tcp (v6) on eth0   DENY       Anywhere (v6)

Was this article helpful?