INSTALL OPENSSH SERVER

ใน กรณีนี้ ยังไม่มีการติดตั้ง OPENSSH SERVER หรือมีแล้วแต่ต้องการใช้คนละ port
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
#apt install libzstd1 zlib1g libssh-4 libssh-dev libssl3 libc6-dev libc6 libcrypt-dev
#apt-get install libssl-dev
#apt install netcat lsof wget diffutils
#apt-get install libpam0g-dev

2. เข้า https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/ เพื่อตรวจสอบ Version ล่าสุด (ตอนที่เขียนบทความคือ Version 9.6p1)
#VER=9.6p1
#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=/opt/openssh-${VER}  --enable-pam --with-pam
#make
#make install

#rm -vf /opt/openssh-latest /etc/ssh-latest
#ln -fvs /opt/openssh-${VER} /opt/openssh-latest
#ln -fvs /opt/openssh-latest/etc /etc/ssh-latest

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

4. เพิ่ม Service ssh
#cd /usr/lib/systemd/system/
####สร้างแฟ้ม ssh-latest.service

[Unit]
Description=OpenBSD Secure Shell server
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target auditd.service
ConditionPathExists=!/opt/openssh-latest/etc/sshd_not_to_be_run

[Service]
EnvironmentFile=-/etc/default/ssh
ExecStartPre=/opt/openssh-latest/sbin/sshd -t
ExecStart=/opt/openssh-latest/sbin/sshd -D $SSHD_OPTS
ExecReload=/opt/openssh-latest/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-lastest.service

####สร้างแฟ้ม ssh-latest@.service

[Unit]
Description=OpenBSD Secure Shell server per-connection daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=auditd.service

[Service]
EnvironmentFile=-/opt/openssh-latest/default/ssh
ExecStart=/opt/openssh-latest/sbin/sshd -i $SSHD_OPTS
RuntimeDirectory=sshd-latest
StandardInput=socket
RuntimeDirectoryPreserve=yes
RuntimeDirectoryMode=0755

 

####สร้างแฟ้ม ssh-latest.socket

[Unit]
Description=OpenBSD Secure Shell server socket
Before=ssh.service
Conflicts=ssh.service
ConditionPathExists=!/opt/openssh-latest/etc/sshd_not_to_be_run

[Socket]
ListenStream=22
Accept=yes

[Install]
WantedBy=sockets.target


####สร้างแฟ้ม rescue-ssh-latest.target

[Unit]
Description=Rescue with network and ssh
Requires=network-online.target ssh-latest.service
After=network-online.target ssh-latest.service

#mkdir -vp /opt/openssh-latest/default/

#cp -av /etc/default/ssh /opt/openssh-latest/default/

#systemctl enable ssh-latest.service
#systemctl enable ssh-latest.socket
#systemctl daemon-reload
#systemctl start ssh-latest

#journalctl -f -x -u ssh-latest

#systemctl status ssh-latest

Rating

Average: 5 (1 vote)