3

I need to login to a linux container hosted in an app service via SSH (the image doesn't have it installed) in order to copy some files. Is there a way to do this via the portal? I'd like to avoid extending the image if possible. I tried fiddling with the startup command available in the UI with no luck.

Thanks!

Gonzalo
  • 679
  • 1
  • 8
  • 18

2 Answers2

5

For the Web App, SSH is supported, but you need to configure the SSH yourself when you use the custom image. Only the built-in images which Azure Web App provided can use the SSH directly without configuring yourself. When you use the built-in image, you can go into the Kudu and the SSH is already configured there.

enter image description here enter image description here

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • Is it possible to configure ssh or something equivalent for the windows-based containers? – zygimantus Sep 24 '21 at 10:20
  • Yes, follow this instruction here for windows configuration - https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux#enable-ssh – Uzzi Emuchay Aug 13 '23 at 14:46
0

I am running my Docker Container in local machine, to Use SSH utility I have perform following steps

Step 1: Login to Docker Container using docker command

$ docker exec -it <container_id or container_name> /bin/bash

Step 2: Install SSH Server

$ apt-get update && apt-get install -y openssh-server

**Step 3 Create SSH-keypair in your local machine **

You can Skip this step if you have SSH-keypair in your ~/.ssh directory

$ ssh-keygen
  • Keep Default Path for storing Key Pair.
  • and for this Enter passphrase (empty for no passphrase): Just press Enter

Step 4: Copy the Content of Public key file to Docker ~/.ssh/authorized_keys file

  • From Local machine

$ cat ~/.ssh/id_rsa.pub

Now Copy that Public Key

  • Inside Docker container

$ mkdir -p ~/.ssh && chmod 700 ~/.ssh

$ echo "<Public-Key content>" > ~/.ssh/authorized_keys

$ chmod 600 ~/.ssh/authorized_keys

Step 5: Update SSH Configuration and restart SSH Service Inside Docker Container

Open file /etc/ssh/sshd_config and remove comment from following line

PubkeyAuthentication yes

This command is use to restart SSH Service to affect the changes.

$ service ssh restart

and Check the status of SSH Service to check it's running or not

$ service ssh status 

Step 6: Get Docker Container I.P.

From Local machine run following Command

$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name or container_id>

Step 7:Perform SSH

$ ssh root@<Container_IP>

You can also use SCP.

$ scp <file_name> root@<container_ip>:
Achyut Vyas
  • 471
  • 1
  • 6
  • 18