INSTALL OPENSSH SERVER

ใน กรณีนี้ ยังไม่มีการติดตั้ง OPENSSH SERVER หรือมีแล้วแต่ต้องการใช้คนละ port
0.1 ติดตั้ง Telnet Server ในกรณีที่ remote มาที่เครื่อง Server ไม่ได้นั่งหน้าเครื่อง
0.2 ถอน openssh-server ของเดิมก่อน
#sudo apt-get remove openssh-server openssh-client
#sudo apt autoremove

1. ติดตั้ง packect ที่จำเป็น
#sudo su -
#apt-get update && apt-get upgrade

#apt install libssl-dev gcc g++ gdb cpp make cmake libtool libc6 autoconf automake pkg-config build-essential gettext libzstd1 zlib1g libssh-4 libssh-dev libssl3 libc6-dev libc6 libcrypt-dev libssl-dev lsof wget diffutils libpam0g-dev

2. เข้า https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/ เพื่อตรวจสอบ Version ล่าสุด (ตอนที่แก้ไขบทความคือ Version 9.9p2)
#VER=9.9p2
#wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${VER}.tar.gz
#wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${VER}.tar.gz.asc
#wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/RELEASE_KEY.asc
#gpg --import RELEASE_KEY.asc
#gpg --verbose --verify openssh-${VER}.tar.gz.asc

#tar -xvf openssh-${VER}.tar.gz
#cd openssh-${VER}

3. ติดตั้ง OPENSSH SERVER

#install -v -g sys -m700 -d /var/lib/sshd
#./configure --prefix=/usr --sysconfdir=/etc/ssh --with-privsep-path=/var/lib/sshd --with-default-path=/usr/bin --with-superuser-path=/usr/sbin:/usr/bin --with-pid-dir=/run --enable-pam --with-pam
#make
#make install

edit port ssh to another port
#nano /etc/ssh/sshd_config
Port 24

4. เพิ่ม user
#useradd -g nogroup -s /usr/sbin/nologin sshd

5. เพิ่ม Service ssh
#cd /usr/lib/systemd/system/
####สร้างแฟ้ม ssh.service
[Unit]
Description=OpenBSD Secure Shell server
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run

[Service]
EnvironmentFile=-/etc/default/ssh
ExecStartPre=/usr/sbin/sshd -t
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/usr/sbin/sshd -t
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
RuntimeDirectory=sshd
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
Alias=sshd.service

####สร้างแฟ้ม ssh.socket
[Unit]
Description=OpenBSD Secure Shell server socket
Before=sockets.target ssh.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run

[Socket]
ListenStream=22
#Port ที่ใช้
Accept=no
FreeBind=yes

[Install]
WantedBy=sockets.target
RequiredBy=ssh.service

####สร้างแฟ้ม rescue-ssh.target
[Unit]
Description=Rescue with network and ssh
Documentation=man:systemd.special(7)
Requires=network-online.target ssh.service
After=network-online.target ssh.service
AllowIsolate=yes

สร้างแฟ้ม /etc/default/ssh
# Default settings for openssh-server. This file is sourced by /bin/sh from
# /etc/init.d/ssh.

# Options to pass to sshd
SSHD_OPTS=


#systemctl enable ssh
#systemctl daemon-reload
#systemctl start ssh

#journalctl -f -x -u ssh

#systemctl status ssh

0.3 ปิด Telnet Server

Rating

Average: 5 (1 vote)