DEV Community

Phongphan Phienphanich
Phongphan Phienphanich

Posted on

ติดตั้ง tmate server

หลังจากที่ได้ลองเล่น tmate มาสักพักใหญ่ รู้สึกประทับใจในความเร็ว และความสะดวกมากมาย (แม้ยังติดปัญหาเล็กน้อยในการใช้ ssh บน Windows)

วันนี้มีคนใจดีบริจาค VPS มาให้ลองเล่น tmate server เลยจัดไปสักหน่อย เดี๋ยวเสียน้ำใจ 555+ มาลุยกันเลย

ติดตั้ง tmate server

เริ่มต้นจากสร้าง Private Key สำหรับ tmate server ก่อน

curl -fsSL https://raw.githubusercontent.com/tmate-io/tmate-ssh-server/master/create_keys.sh | bash
Enter fullscreen mode Exit fullscreen mode

Screenshot 2021-01-16 121827

จดสองบรรทัดสุดท้ายไว้ เพราะเราต้องไป Set ให้เครื่องที่ต้องการต่อ tmate

จากนั้นลง docker engine (ในเครื่องใครมีแล้วก็ข้ามได้)

curl -fsSL https://get.docker.com | bash
Enter fullscreen mode Exit fullscreen mode

สุดท้ายก็สั่งรัน tmate-server image

docker run -itd --name tmate -v $PWD/keys:/keys --cap-add SYS_ADMIN -e SSH_KEYS_PATH=/keys -e SSH_HOSTNAME=<hostname> -p 2200:2200  tmate/tmate-ssh-server
Enter fullscreen mode Exit fullscreen mode

โดยที่ <hostname> คือ domain ที่จะใช้ในการ connect tmate

ตั้งค่าเครื่องที่ต้องการใช้ tmate

ติดตั้ง tmate ที่เครื่อง ตามบทความก่อนหน้า แล้วตั้งค่าไฟล์ ~/.tmate.conf ดังนี้

set -g tmate-server-host "<hostname>"
set -g tmate-server-port 2200
set -g tmate-server-rsa-fingerprint SHA256:tU84BnNHSoqk6o+fB96xPu7Hoikr3GNrz8+o9bIAp3M
set -g tmate-server-ed25519-fingerprint SHA256:2gohOJWkDjf+6t8OAbEW/fk8z1w2UbXFHa3mjoxEmWA
Enter fullscreen mode Exit fullscreen mode

สองบรรทัดสุดท้ายคือที่ได้จากขั้นตอนการสร้าง Private Key ข้างบน จากนั้นรันคำสั่ง tmate ตามปกติ

Screenshot 2021-01-16 124718

หยุดตรงนี้ก็ได้ แต่ใครจะไปต่อก็จัดไป

สร้าง Easy Install Script (Docker Image)

เพื่อให้ไปตั้งค่าในเครื่องใหม่ง่ายขึ้น หรือจะส่งให้ปลายทางติดตั้งได้ง่าย ก็ควรจะต้องทำ script อัตโนมัติให้ ขั้นตอนจะได้ไม่เยอะ สามารถทำได้โดย

สร้าง Docker โดยมีไฟล์ต่างๆ ดังนี้
Screenshot 2021-01-16 123113

Dockerfile

FROM nginx:alpine

ADD nginx.conf /etc/nginx/
ADD *.sh /usr/share/nginx/html/
Enter fullscreen mode Exit fullscreen mode

nginx.conf

worker_processes 2;

events { worker_connections 1024; }

http {
    include    mime.types;
    sendfile on;
    server {
        root /usr/share/nginx/html/;
        index install.sh;
        server_name t.ondev.link;
        listen 80;
    }
}
Enter fullscreen mode Exit fullscreen mode

install.sh

#!/bin/bash
set -e

# t.ondev.link tmate installation script
# This script is meant for quick & easy install via:
#   $ curl -fsSL http://<hostname> | bash

arch=$(dpkg --print-architecture)

curl -fL https://github.com/tmate-io/tmate/releases/download/2.4.0/tmate-2.4.0-static-linux-${arch}.tar.xz -o /tmp/tmate.tar.xz

tar -xvf /tmp/tmate.tar.xz > /dev/null
mv tmate-*/tmate /usr/local/bin/
chmod +x /usr/local/bin/

rm -rf tmate-* /tmp/tmate.tar.xz

echo "set -g tmate-server-host \"<hostname>\"" > ~/.tmate.conf
echo "set -g tmate-server-port 2200" >> ~/.tmate.conf
echo "set -g tmate-server-rsa-fingerprint SHA256:tU84BnNHSoqk6o+fB96xPu7Hoikr3GNrz8+o9bIAp3M" >> ~/.tmate.conf
echo "set -g tmate-server-ed25519-fingerprint SHA256:2gohOJWkDjf+6t8OAbEW/fk8z1w2UbXFHa3mjoxEmWA" >> ~/.tmate.conf

echo "Done"
Enter fullscreen mode Exit fullscreen mode

** อย่าลืมแก้ค่า <hostname> และ SHA256 ทั้งสองบรรทัดสุดท้าย **

เมื่อพร้อมแล้วก็สร้าง docker image และรันได้เลย

docker build -t tmate-setup .
docker run -itd -p 80:80 --name tmate-setup tmate-setup
Enter fullscreen mode Exit fullscreen mode

เมื่อเรียบร้อย ก็แจ้งให้ปลายทางรันคำสั่ง

curl -fsSL http://<hostname> | bash
Enter fullscreen mode Exit fullscreen mode

คำสั่งนี้จะติดตั้งและตั้งค่าทั้งหมดให้ ปลายทางก็สามารถรัน tmate ต่อได้เลยครับ ezez

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More