Docker - Ubuntu SSH Setup

Docker - Ubuntu SSH Setup
Host: Use the same port -> just change to the SSH port that does not conflict with NAS.
Environment Settings for Ubuntu Container
Dockerfile
1 | FROM ubuntu:latest |
Docker Build and Push to Docker Hub
1 | docker build -t ubuntu_ssh . |
Install OpenSSH-Server
1 | apt-get update |
Pull and Run the ubuntu_ssh Image
Pull ubuntu_ssh from Docker Hub
1 | sudo docker pull wulukewu/ubuntu_ssh:latest |
Run ubuntu_ssh in Host
1 | sudo docker run -d --net=host --name ubuntu_ssh wulukewu/ubuntu_ssh:latest |
Access the Ubuntu Container
1 | sudo docker exec -i -t ubuntu_ssh /bin/bash |
Hostname Configuration
Change Hostname
1 | sudo nano /etc/hostname |
Display the Current Hostname
1 | hostname |
SSH Configuration
Change SSH Port
1 | sudo nano /etc/ssh/sshd_config |
User Management
Add a New Sudo User
1 | adduser user_name |
Add the User to the Sudo Group
1 | usermod -aG sudo user_name |
Change User Password
1 | sudo passwd user_name |
Test Sudo Access
1 | su - user_name |
References
- How to SSH into a Docker Container | Step-by-Step Tutorial
- Save Docker Image as a File
- Ubuntu Linux Change Hostname
- Day 21: Introduction to Docker Networking (Part 2)
- Docker Basic Commands Cheat Sheet
- How to Create a New Sudo-Enabled User on Ubuntu
- Change Password for Root and User Accounts
- Ask ChatGPT