Skip to content

Tsaihemanth150/Docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Secure File Transfer Using Docker

This repository provides a Docker setup for securely transferring files between Windows and Linux (or any Docker host) using an Ubuntu container with SSH enabled. You can use scp (Secure Copy Protocol) to push and pull files through the container’s SSH server.


πŸ“‹ Prerequisites

  • Docker installed on your system
  • Basic familiarity with the command line (PowerShell, Bash, etc.)
  • A text editor to review or modify the Dockerfile

πŸ› οΈ Dockerfile Overview

# Use the official Ubuntu image as the base
FROM ubuntu:latest

# Set environment variables to avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# Update the package list and install necessary packages
RUN apt-get update && \
    apt-get install -y \
      openssh-server \
      nano \
      vim \
      net-tools \
      curl \
      wget \
      fail2ban && \
    mkdir /var/run/sshd && \
    echo 'root:root' | chpasswd && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed -i 's/#PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config

# Enable fail2ban service to protect SSH (requires systemd; see notes below)
RUN systemctl enable fail2ban

# Expose the SSH port
EXPOSE 22

# Start SSHD in the foreground
CMD ["/usr/sbin/sshd", "-D"]
  • Base image: ubuntu:latest
  • SSH server: Installed and configured to allow root login with password
  • Fail2Ban: Enabled to protect against brute‑force attacks
  • Exposed port: 22 for SSH

πŸš€ Build and Run

  1. Build the Docker image

    docker build -t my_ubuntu_ssh .
  2. Run the container

    docker run -d \
      --name scptest \
      -p 2222:22 \
      my_ubuntu_ssh
    • Maps host port 2222 β†’ container port 22
    • Root password is set to root (see Security Notes)
  3. Verify SSH is running

    docker ps
    # Should show your scptest container listening on 0.0.0.0:2222->22/tcp

πŸ” Security Notes

  • Root login: Enabled for demonstration. In production, create a non‑root user with SSH keys.
  • Passwords: The root password is root. Change it in the Dockerfile (echo 'root:<your-password>') or use key-based auth.
  • Fail2Ban: Requires systemd to run properly inside container; you may need a workaround or external firewall rules.

πŸ“‚ Transferring Files with SCP

From your host machine (Windows PowerShell, Git Bash, or Linux shell):

  • Upload a file to the container:
    scp -P 2222 path/to/local/file.txt root@localhost:/root/
  • Download a file from the container:
    scp -P 2222 root@localhost:/root/file.txt path/to/local/destination/

Replace path/to/... with your actual file paths.


πŸ”„ Persisting Files

To persist files between container restarts, mount a host directory:

docker run -d \
  --name scptest \
  -p 2222:22 \
  -v /path/on/host:/root/transfer \
  my_ubuntu_ssh
  • Files uploaded to /root/transfer inside the container will live on your host at /path/on/host.

🧹 Cleanup

  • Stop & remove container:
    docker stop scptest
    docker rm scptest
  • Remove image:
    docker rmi my_ubuntu_ssh

πŸ“– Further Reading


πŸ“„ License

This project is released under the MIT License. Feel free to use, modify, and distribute!

Packages

No packages published