Press "Enter" to skip to content

ubuntu install ssh server in docker

FROM ubuntu:latest

# Install OpenSSH Server and create necessary directory
RUN apt-get update && apt-get install -y openssh-server && \
    mkdir /var/run/sshd

# Set a password for the root user (change 'your_password' to a secure one)
RUN echo 'root:your_password' | chpasswd

# Modify SSH config to allow root login with password and fix PAM issue
RUN sed -i 's/^#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed 's@session\\s*required\\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

# Expose port 22
EXPOSE 22

# Start SSH server in detached mode
CMD ["/usr/sbin/sshd", "-D"]
发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注