Thursday, December 28, 2023

Enable SSH in Azure Webapp Container

 Enable SSH in Azure Webapp Container


    This article will help you enable ssh in Azure Webapp container.

- Create a file called "init.sh" at the same location where your Dockerfile is and add below content to it.

#!/bin/bash
set -e

echo "Starting SSH ..."
service ssh start

exec "$@"

- Create a file called "sshd_config", this file will have basic SSH configuration and port for SSH
and add below content.

Port 2222 ListenAddress 0.0.0.0 LoginGraceTime 180 X11Forwarding yes Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr MACs hmac-sha1,hmac-sha1-96 StrictModes yes SyslogFacility DAEMON PasswordAuthentication yes PermitEmptyPasswords no PermitRootLogin yes Subsystem sftp internal-sftp

- Install OpenSSH service, add below lines in Dockerfile.

# Install and Run SSH
ENV SSH_PASSWD "root:Docker!"
RUN apt-get update
RUN apt-get install -y dialog \
    && apt-get update \
    && apt-get install -y openssh-server \
    && echo "$SSH_PASSWD" | chpasswd

COPY ./sshd_config /etc/ssh/
COPY ./init.sh /usr/local/bin/
RUN chmod u+x /usr/local/bin/init.sh
ENTRYPOINT ["init.sh"]

- Build Docker image and deploy it on Azure webapp, to validate SSH navigate to Azure Portal.


Login into your Azure Portal–> Navigate to App services–> Enter into your deployed App service–>
Click on SSH(from the side pane)–> Click on Go


It will open another tab in browser and login to container.