tmate-io / tmate

Instant Terminal Sharing

Home Page:https://tmate.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not able to connect tmate client

agrawawl-ric opened this issue · comments

I have created tmate-ssh-server on docker container with the below docker file:

  • Dockerfile:

tmateserver@tmateserver:~$ vi Dockerfile
apt-get install -y build-essential cmake libmsgpack-dev libssl-dev
libssh-dev libutempter-dev zlib1g-dev wget openssh-server autoconf
automake libtool pkg-config libevent-dev libncurses-dev

Download and install tmate

Download and install tmate

RUN wget https://github.com/tmate-io/tmate/archive/2.4.0.tar.gz -O tmate.tar.gz &&
tar -zxvf tmate.tar.gz &&
cd tmate-2.4.0 &&
./autogen.sh &&
./configure &&
make &&
make install

Set up SSH server

RUN mkdir /var/run/sshd &&
echo 'root:rootpassword' | chpasswd &&
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config &&
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config &&
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config &&
sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config

Add a user for tmate

RUN useradd -ms /bin/bash tmateuser && echo "tmateuser:tmatepassword" | chpasswd

Set up tmate

RUN mkdir -p /home/tmateuser/.tmate
COPY tmate.conf /home/tmateuser/.tmate.conf
RUN chown tmateuser:tmateuser /home/tmateuser/.tmate.conf

Expose SSH port

EXPOSE 22

Start SSH and tmate

#CMD ["/usr/sbin/sshd", "-D"]

Start SSH and tmate

CMD service ssh start && tail -f /dev/null

  • Created tmate.conf file in host machine tmate.conf:
    set -g tmate-server-host 127.0.0.1
    set -g tmate-server-port 2222
    set -g tmate-ssh-port 2222

Step 2: Build and Run the Docker Container
Build the Docker image:
docker build -t tmate-server .

- Run the Docker container:
docker run -d -p 2222:2222 --name tmate-server-container tmate-server

Step 3: Configure SSH Access and Key Authentication
Generate an SSH key on the host machine :

ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -N ""
Copy the public key to the container's authorized_keys for tmateuser:
docker cp ~/.ssh/id_rsa.pub tmate-server-container:/home/tmateuser/id_rsa.pub
docker exec -it tmate-server-container bash
mkdir -p /home/tmateuser/.ssh
cat /home/tmateuser/id_rsa.pub >> /home/tmateuser/.ssh/authorized_keys
chown -R tmateuser:tmateuser /home/tmateuser/.ssh
chmod 600 /home/tmateuser/.ssh/authorized_keys
exit

Step 4: Connect Using the Tmate Client
On the host machine, create a Tmate session and connect to the Tmate server:
tmate -S /tmp/tmate.sock new-session -d
tmate -S /tmp/tmate.sock wait tmate-ready
tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}'

Step no.4 is not giving output
tmate -S /tmp/tmate.sock wait tmate-ready-----------This command takes forever
tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}'-------------This command give no output