Skip to content

Instantly share code, notes, and snippets.

@udkyo
Last active May 1, 2024 12:51
Show Gist options
  • Save udkyo/c20935c7577c71d634f0090ef6fa8393 to your computer and use it in GitHub Desktop.
Save udkyo/c20935c7577c71d634f0090ef6fa8393 to your computer and use it in GitHub Desktop.
Basic container for X11 forwarding goodness
FROM ubuntu
RUN apt update \
&& apt install -y firefox \
openssh-server \
xauth \
&& mkdir /var/run/sshd \
&& mkdir /root/.ssh \
&& chmod 700 /root/.ssh \
&& ssh-keygen -A \
&& sed -i "s/^.*PasswordAuthentication.*$/PasswordAuthentication no/" /etc/ssh/sshd_config \
&& sed -i "s/^.*X11Forwarding.*$/X11Forwarding yes/" /etc/ssh/sshd_config \
&& sed -i "s/^.*X11UseLocalhost.*$/X11UseLocalhost no/" /etc/ssh/sshd_config \
&& grep "^X11UseLocalhost" /etc/ssh/sshd_config || echo "X11UseLocalhost no" >> /etc/ssh/sshd_
config
RUN echo "YOUR_PUB_KEY_HERE" >> /root/.ssh/authorized_keys
ENTRYPOINT ["sh", "-c", "/usr/sbin/sshd && tail -f /dev/null"]
@Tangolin
Copy link

@peter279k I tried using that dockerfile instead and building by your instructions, it returns the following error

New password: Retype new password: Password change aborted.
passwd: Authentication token manipulation error
passwd: password unchanged
The command '/bin/sh -c apt update     && apt install -y firefox                       openssh-server                       xauth     && mkdir /var/run/sshd     && mkdir /root/.ssh     && chmod 700 /root/.ssh     && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config     && sed -i "s/^.*X11Forwarding.*$/X11Forwarding yes/" /etc/ssh/sshd_config     && sed -i "s/^.*X11UseLocalhost.*$/X11UseLocalhost no/" /etc/ssh/sshd_config     && grep "^X11UseLocalhost" /etc/ssh/sshd_config || echo "X11UseLocalhost no" >> /etc/ssh/sshd_config     && cat /password.txt /password.txt | passwd     && rm /password.txt' returned a non-zero code: 10

I think I did follow it step by step without any other manipulations. I am rather new to this so very sorry if I am making some stupid mistake.

@AutomationMusician I do have X11 forwarding via PuTTY, ran xclock on the remote server and could get the display on my local machine.

@peter279k
Copy link

Do you have the password.txt file? It seems that you don't have the password.txt file and this file and Dockerfile are same file path.

@peter279k
Copy link

And the sample password.txt file contents are as follows:

your-password

@Tangolin
Copy link

Oh I have managed to get past the password part, appears I didn't add the UNIX newline character, thank you so much for you help!

@baogorek
Copy link

baogorek commented Mar 22, 2023

Very helpful stuff here but the the content has traveled some since the initial post. Steps I used:

  1. @AutomationMusician's April 2018 post with the password file trick
  2. @peter279k's suggestion to use FROM ubuntu:18.04 (edit: just tried again with 22.04 and it was fine) and his other steps on July 16, 2021. If you ssh in without filrefox on the end you can just type it at the terminal

Note that if you're working in a text editor that automatically adds a newline, like vim, don't add a blank line as it will do that for you (and the blank line will break it).

Might come back for the ssh keys-based method later.

I'm on MacOS and it's interesting to me that nowhere was the DISPLAY environment variable mentioned, or volume informations specified (e.g., '-v /tmp/.X11-unix:/tmp/.X11-unix'). These were huge red herrings in my attempts to figure this out.

@zhenguoli
Copy link

Thanks. It also works for foreign architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment