Sign inSign up

oaklight/ssh-interactive-auth-sample-server

By oaklight

•Updated 8 months ago

Dockerized OpenSSH server with keyboard-interactive auth for testing 2FA flows.

Image
0

1.4K

oaklight/ssh-interactive-auth-sample-server repository overview

⁠SSH Interactive Auth Sample Server

This project provides a Dockerized SSH server configured to require keyboard-interactive authentication (simulating 2FA). It is designed for testing SSH clients that need to handle interactive prompts, such as autossh-cli auth.

⁠Features

  • OpenSSH Server: Runs a standard OpenSSH server on port 2222.
  • Keyboard-Interactive Auth: Configured to require keyboard-interactive authentication.
  • Google Authenticator: Uses libpam-google-authenticator to simulate 2FA.
  • Pre-configured User: Creates a user testuser with password testpass and a pre-generated 2FA secret.

⁠Prerequisites

  • Docker
  • Docker Compose (optional, but recommended)
  • Make (optional)

⁠Usage

  1. Build and Start:

    make up
    

    To use a registry mirror:

    REGISTRY_MIRROR=docker.1ms.run make up
    
  2. View Logs:

    make logs
    
  3. Stop:

    make down
    
  4. Clean:

    make clean
    
⁠Using Docker Compose Directly
  1. Start:

    docker compose up -d --build
    
  2. Stop:

    docker compose down
    

⁠Testing Connection

To test the connection, use an SSH client:

ssh -p 2222 testuser@localhost

You will be prompted for:

  1. Password: testpass
  2. Verification code: You need the current TOTP code.
⁠Getting the Verification Code

Since the 2FA secret is generated inside the container, you have two options:

  1. Get the Secret Key: Run the following command to see the secret key (first line):

    docker exec -it ssh-interactive-auth cat /home/testuser/.google_authenticator | head -n 1
    

    Use this key in a TOTP app (like Google Authenticator) or a CLI tool (like oathtool) to generate the code.

    Example with oathtool:

    SECRET=$(docker exec ssh-interactive-auth head -n 1 /home/testuser/.google_authenticator)
    oathtool --totp -b "$SECRET"
    
  2. Scan the QR Code: If you want to scan the QR code with your phone, you can view the generated file content (which might contain a URL or ASCII QR code if generated with those options, though the current setup is minimal):

    docker exec -it ssh-interactive-auth cat /home/testuser/.google_authenticator
    

    Note: The current setup script uses -C which might not output the QR code to the file. Using the secret key is more reliable for testing.

⁠Configuration Details

  • sshd_config:

    • PasswordAuthentication no
    • ChallengeResponseAuthentication yes
    • UsePAM yes
    • AuthenticationMethods keyboard-interactive
  • PAM:

    • Configured in config/pam.d/sshd to use pam_google_authenticator.so.

⁠License

MIT

Tag summary

Content type

Image

Digest

sha256:a0130bb0b…

Size

84.8 MB

Last updated

8 months ago

docker pull oaklight/ssh-interactive-auth-sample-server