Cara Mengkonfigurasi Server OpenSSH di FreeBSD

· 2 min read

Protokol SSH pertama kali dikembangkan pada tahun 1995 oleh Tatu Ylonen, seorang peneliti dari Universitas Teknologi Helsinki. Ylonen mendirikan SSH C

OpenSSH adalah seperangkat utilitas sumber terbuka yang mengimplementasikan protokol SSH (Secure Shell). SSH adalah versi aman dari telnet. SSH menyediakan akses bagi administrator dan pengguna ke sistem jarak jauh seolah-olah mereka secara fisik berada di konsol. SSH menggunakan enkripsi untuk mencegah penyadapan pada koneksi yang dibuat antara klien dan server. OpenSSH menguasai 87 persen pasar konsol jarak jauh. Penggunaan OpenSSH sangat praktis dan dapat diterapkan pada semua distribusi Linux dan BSD, serta Apple Mac OS.

Protokol SSH pertama kali dikembangkan pada tahun 1995 oleh Tatu Ylonen, seorang peneliti dari Universitas Teknologi Helsinki. Ylonen mendirikan SSH Communications Security pada akhir tahun 1995 untuk mengembangkan dan memasarkan SSH. Perusahaannya saat ini memasarkan SSH Server/Client Tectia. OpenSSH awalnya dibuat oleh tim OpenBSD sebagai bagian dari rilis OpenBSD 2.6 pada bulan Desember 1999.

Tim tersebut menggunakan kode dari proyek SSH Tatu Ylonen, yang awalnya merupakan sumber terbuka. Perbaikan bug dan penambahan fitur pada rilis OpenSSH. Segera setelah OpenSSH dirilis, para pengembangnya memutuskan untuk membagi diri menjadi dua tim. Satu kelompok berkonsentrasi pada pengembangan OpenSSH untuk OpenBSD sementara kelompok lain mengembangkan versi portabel OpenSSH untuk digunakan pada platform lain. Edisi portabel memiliki huruf P yang ditambahkan pada versi tersebut untuk menunjukkan hal ini. OpenSSH terus dikembangkan oleh tim OpenBSD yang dipimpin oleh pendirinya, Theo de Raadt.


OpenSSH di FreeBSD stable


Dalam artikel ini, kami akan menjelaskan tentang OpenSSH, khususnya yang terkait dengan penginstalan dan konfigurasi OpenSSH pada sistem FreeBSD. OpenSSH merupakan bagian dari distribusi standar FreeBSD. Dalam artikel ini, kami akan mengganti versi dasar dengan versi OpenSSH yang lebih baru yang diambil dari koleksi port FreeBSD. Untuk memulai proses penginstalan OpenSSH, ketik baris perintah berikut.


root@ns1:~ # cd /usr/ports/security/openssh-portable
root@ns1:/usr/ports/security/openssh-portable # make -D WITH_OVERWRITE_BASE install clean
Setelah proses instalasi selesai, saatnya mengonfigurasi OpenSSH untuk digunakan pada sistem FreeBSD. Tambahkan skrip "NO_OPENSSH = YES" ke berkas /etc/make.conf di /etc. Skrip ini berguna untuk memberi tahu make agar tidak membuat versi dasar OpenSSH dan mencegah sistem menurunkan versi OpenSSH ke versi dasar yang lebih lama.

root@ns1:/usr/ports/security/openssh-portable # echo "NO_OPENSSH = YES" >> /etc/make.conf
Langkah selanjutnya adalah menghapus folder SSH bawaan sistem FreeBSD, yaitu folder "/etc/ssh", lalu kita ganti dengan symlink dari folder di "/usr/local/etc/ssh".

root@ns1:/usr/ports/security/openssh-portable # rm -rf /etc/ssh
root@ns1:/usr/ports/security/openssh-portable # ln -s /usr/local/etc/ssh /etc
Setelah proses pembuatan symlink selesai, kita lanjutkan dengan membuat skrip Startup rc.d, yang digunakan untuk memulai Server OpenSSH secara otomatis saat komputer dinyalakan. Untuk membuat Startup rc.d, kita edit berkas /etc/rc.conf dan tambahkan skrip berikut ke berkas /etc/rc.conf.

root@ns1:/usr/ports/security/openssh-portable # ee /etc/rc.conf
sshd_enable="NO"
openssh_enable="YES"
openssh_flags=""
openssh_pidfile="/var/run/sshd.pid"
Berikutnya kita edit berkas konfigurasi SSH yaitu berkas /usr/local/etc/ssh/sshd_config.

root@ns1:~ # cd /usr/local/etc/ssh
root@ns1:/usr/local/etc/ssh # ee sshd_config

#	$OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.
# Note that some of FreeBSD's defaults differ from OpenBSD's, and
# FreeBSD has a few additional options.

Port 22
#AddressFamily any
ListenAddress 192.168.5.2
#ListenAddress ::
##AllowUsers udin@192.168.5.2

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
LogLevel VERBOSE
# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile	.ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes

# Change to yes to enable built-in password authentication.
# Note that passwords may also be accepted via KbdInteractiveAuthentication.
PasswordAuthentication yes
PermitEmptyPasswords no

# Change to no to disable PAM authentication
#KbdInteractiveAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'no' to disable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin prohibit-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
#UsePAM yes

AllowAgentForwarding yes
AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd yes
#PrintLastLog yes
TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory /usr/local/etc/ssh
#UseBlacklist no
#VersionAddendum FreeBSD-20230316

# no default banner path
#Banner none
Banner /usr/local/etc/ssh/banner
# override default of no subsystems
Subsystem	sftp	/usr/libexec/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	PermitTTY no
#	ForceCommand cvs server
Dalam skrip di atas OpenSSH berjalan pada port 22 dan menggunakan alamat IP internal/pribadi server FreeBSD kita, yaitu 192.168.5.2.


1. Membuat Kunci OpenSSH

Server SSH mengautentikasi klien menggunakan sejumlah teknik yang berbeda. Mekanisme autentikasi yang paling sering digunakan adalah kata sandi dan kunci SSH. Meskipun kata sandi memberikan perlindungan terhadap akses yang tidak diinginkan, kunci SSH sejauh ini lebih aman. Masalah dengan kata sandi adalah kata sandi sering kali dibuat secara manual dan kurang panjang serta rumit.

Oleh karena itu, serangan peretas dapat membahayakan keamanannya. Kunci SSH menyediakan opsi yang aman secara konsisten. Setiap pasangan kunci SSH terdiri dari kunci pribadi dan kunci publik yang cocok, dan dapat digunakan sebagai pengganti kata sandi untuk autentikasi. Ikuti langkah-langkah di bawah ini untuk membuat kunci OpenSSH.

root@ns1:~ # ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):  tekan ENTER
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): masukkan password
Enter same passphrase again:  masukkan password
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:0RflgIyj4gSxDsASSTM3UQsMgYLDO2GYm8lnejbNbXY root@router2
The key's randomart image is:
+---[RSA 3072]----+
|XX=*o.   o .o..  |
|@==oo . o.o  +   |
|*=+. . .... . .  |
|+* oo .  . .     |
|  *oo.. S        |
| . +.o + E       |
|  o . o .        |
|                 |
|                 |
+----[SHA256]-----+
Perintah skrip di atas akan membuat folder baru /root/.ssh, yang berisi file id_rsa (kunci pribadi) dan file id_rsa.pub (kunci publik). Jika pembuatan kunci telah selesai, lanjutkan dengan menginstal kunci SSH publik yang digunakan untuk konsol jarak jauh.

root@ns1:~ # cat ~/.ssh/id_rsa.pub | ssh root@ns1.unixexplore.com "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
The authenticity of host 'router2.unixexplore.com (192.168.9.3)' can't be established.
ED25519 key fingerprint is SHA256:cUadBvuFWb38iZ0cdUR8NtkOehQg8vZ3Vh7MWUTaXI0.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: router2
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'router2.unixexplore.com' (ED25519) to the list of known hosts.
                                                               #####
                                                                #######
                   #                                            ##O#O##
  ######          ###                                           #VVVVV#
    ##             #                                          ##  VVV  ##
    ##         ###    ### ####   ###    ###  ##### #####     #          ##
    ##        #  ##    ###    ##  ##     ##    ##   ##      #            ##
    ##       #   ##    ##     ##  ##     ##      ###        #            ###
    ##          ###    ##     ##  ##     ##      ###       QQ#           ##Q
    ##       # ###     ##     ##  ##     ##     ## ##    QQQQQQ#       #QQQQQQ
    ##      ## ### #   ##     ##  ###   ###    ##   ##   QQQQQQQ#     #QQQQQQQ
  ############  ###   ####   ####   #### ### ##### #####   QQQQQ#######QQQQQ
(root@ns1.unixexplore.com) Password for root@router2:  ketikkan password root
root@ns1:~ #
Langkah selanjutnya adalah menghubungkan server SSH menggunakan kunci pribadi, berikut adalah contoh skrip.

root@ns1:~ # ssh -i ~/.ssh/id_rsa -p 22 root@ns1.unixexplore.com
                                                               #####
                                                                #######
                   #                                            ##O#O##
  ######          ###                                           #VVVVV#
    ##             #                                          ##  VVV  ##
    ##         ###    ### ####   ###    ###  ##### #####     #          ##
    ##        #  ##    ###    ##  ##     ##    ##   ##      #            ##
    ##       #   ##    ##     ##  ##     ##      ###        #            ###
    ##          ###    ##     ##  ##     ##      ###       QQ#           ##Q
    ##       # ###     ##     ##  ##     ##     ## ##    QQQQQQ#       #QQQQQQ
    ##      ## ### #   ##     ##  ###   ###    ##   ##   QQQQQQQ#     #QQQQQQQ
  ############  ###   ####   ####   #### ### ##### #####   QQQQQ#######QQQQQ
Enter passphrase for key '/root/.ssh/id_rsa': masukkan password
Jika frasa sandi digunakan, pengguna akan diminta setiap kali koneksi dibuat dengan server. Anda dapat menggunakan ssh-agent dan ssh-add untuk memuat kunci SSH ke dalam memori dan menghilangkan kebutuhan untuk memasukkan kata sandi setiap saat. ssh-agent menangani autentikasi menggunakan kunci pribadi yang dimasukkan ke dalamnya. ssh-agent dapat digunakan untuk menjalankan shell atau window manager, di antara aplikasi lainnya.

Untuk menggunakan ssh-agent di shell, berikan shell sebagai parameter perintah. Tambahkan identitas dengan menjalankan ssh-add dan memberikan frasa sandi kunci pribadi. Pengguna kemudian akan dapat melakukan ssh ke host mana pun dengan kunci publik terpasang.

root@ns1:~ # ssh-agent csh
root@ns1:~ # ssh-add
Enter passphrase for /root/.ssh/id_rsa: masukkan kata sandi
Identity added: /root/.ssh/id_rsa (root@ns1)
Setelah kunci OpenSSH dibuat, lanjutkan dengan membuat file Banner OpenSSH. Kita beri nama file Banner "banner" dan letakkan di folder /usr/local/etc/ssh dan di file /usr/local/etc/ssh/banner kita masukkan skrip di bawah ini.

root@ns1:~ # touch /usr/local/etc/ssh/banner
root@ns1:~ # ee /usr/local/etc/ssh/banner
                                                               #####
                                                                #######
                   #                                            ##O#O##
  ######          ###                                           #VVVVV#
    ##             #                                          ##  VVV  ##
    ##         ###    ### ####   ###    ###  ##### #####     #          ##
    ##        #  ##    ###    ##  ##     ##    ##   ##      #            ##
    ##       #   ##    ##     ##  ##     ##      ###        #            ###
    ##          ###    ##     ##  ##     ##      ###       QQ#           ##Q
    ##       # ###     ##     ##  ##     ##     ## ##    QQQQQQ#       #QQQQQQ
    ##      ## ### #   ##     ##  ###   ###    ##   ##   QQQQQQQ#     #QQQQQQQ
  ############  ###   ####   ####   #### ### ##### #####   QQQQQ#######QQQQQ
Sekarang aktifkan server OpenSSH, apakah berjalan atau tidak?.

root@ns1:~ # service openssh restart
Performing sanity check on openssh configuration.
Stopping openssh.
Waiting for PIDS: 2481.
Performing sanity check on openssh configuration.
Starting openssh.
root@ns1:~ #
Jika tampilannya seperti di atas, maka server OpenSSH berjalan dengan baik.


2. Log In Dengan Multi User

Salah satu kelebihan server FreeBSD adalah dapat membuat banyak sekali pengguna dan grup. Setiap pengguna dapat terhubung ke server OpenSSH dan dapat mengakses sistem FreeBSD. Kami tidak menjelaskan cara membuat pengguna dan grup di artikel ini, Anda dapat membaca artikel sebelumnya yang membahas teknik membuat pengguna dan grup di FreeBSD.

Dalam artikel ini kami berasumsi server FreeBSD memiliki pengguna dan grup dengan nama-nama berikut:

User Name                   User Password
udin                                routerudin
anto                                routeranto
jaka                                routerjaka
sari                                 routersari

Mari kita beri contoh, misalnya pengguna Udin ingin mengakses server OpenSSH, gunakan skrip berikut.

root@ns1:~ # ssh udin@ns1.unixexplore.com
                                                              #####
                                                                #######
                   #                                            ##O#O##
  ######          ###                                           #VVVVV#
    ##             #                                          ##  VVV  ##
    ##         ###    ### ####   ###    ###  ##### #####     #          ##
    ##        #  ##    ###    ##  ##     ##    ##   ##      #            ##
    ##       #   ##    ##     ##  ##     ##      ###        #            ###
    ##          ###    ##     ##  ##     ##      ###       QQ#           ##Q
    ##       # ###     ##     ##  ##     ##     ## ##    QQQQQQ#       #QQQQQQ
    ##      ## ### #   ##     ##  ###   ###    ##   ##   QQQQQQQ#     #QQQQQQQ
  ############  ###   ####   ####   #### ### ##### #####   QQQQQ#######QQQQQ
(udin@ns1.unixexplore.com) Password for udin@ns1: masukkan password user udin
Last login: Tue Oct 31 21:03:02 2023 from 192.168.5.2
FreeBSD 13.2-RELEASE releng/13.2-n254617-525ecfdad597 GENERIC

Welcome to FreeBSD!

Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories:   https://www.FreeBSD.org/security/
FreeBSD Handbook:      https://www.FreeBSD.org/handbook/
FreeBSD FAQ:           https://www.FreeBSD.org/faq/
Questions List:        https://www.FreeBSD.org/lists/questions/
FreeBSD Forums:        https://forums.FreeBSD.org/

Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with:  pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.

Show the version of FreeBSD installed:  freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages:  man man
FreeBSD directory layout:      man hier

To change this login announcement, see motd(5).
sh (the default Bourne shell in FreeBSD) supports command-line editing.  Just
``set -o emacs'' or ``set -o vi'' to enable it. Use "<TAB>" key to complete
paths.
udin@ns1:~ $
Sekarang kita coba lagi dengan nama pengguna anto. Dalam contoh ini, nama pengguna Anto ingin mengakses server SSH. Berikut ini contohnya.

udin@ns1:~ $ ssh anto@192.168.5.2
                                                              #####
                                                                #######
                   #                                            ##O#O##
  ######          ###                                           #VVVVV#
    ##             #                                          ##  VVV  ##
    ##         ###    ### ####   ###    ###  ##### #####     #          ##
    ##        #  ##    ###    ##  ##     ##    ##   ##      #            ##
    ##       #   ##    ##     ##  ##     ##      ###        #            ###
    ##          ###    ##     ##  ##     ##      ###       QQ#           ##Q
    ##       # ###     ##     ##  ##     ##     ## ##    QQQQQQ#       #QQQQQQ
    ##      ## ### #   ##     ##  ###   ###    ##   ##   QQQQQQQ#     #QQQQQQQ
  ############  ###   ####   ####   #### ### ##### #####   QQQQQ#######QQQQQ
(anto@192.168.5.2) Password for anto@ns1: masukkan password username anto
Last login: Tue Oct 31 21:01:35 2023 from 192.168.5.2
FreeBSD 13.2-RELEASE releng/13.2-n254617-525ecfdad597 GENERIC

Welcome to FreeBSD!

Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories:   https://www.FreeBSD.org/security/
FreeBSD Handbook:      https://www.FreeBSD.org/handbook/
FreeBSD FAQ:           https://www.FreeBSD.org/faq/
Questions List:        https://www.FreeBSD.org/lists/questions/
FreeBSD Forums:        https://forums.FreeBSD.org/

Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with:  pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.

Show the version of FreeBSD installed:  freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages:  man man
FreeBSD directory layout:      man hier

To change this login announcement, see motd(5).
Need to see the calendar for this month? Simply type "cal".  To see the
whole year, type "cal -y".
                -- Dru <genesis@istar.ca>
anto@ns1:~ $
Contoh lain, yaitu kita akan menggunakan pengguna root untuk mengakses server OpenSSH.

anto@ns1:~ $ ssh root@192.168.5.2
                                                              #####
                                                                #######
                   #                                            ##O#O##
  ######          ###                                           #VVVVV#
    ##             #                                          ##  VVV  ##
    ##         ###    ### ####   ###    ###  ##### #####     #          ##
    ##        #  ##    ###    ##  ##     ##    ##   ##      #            ##
    ##       #   ##    ##     ##  ##     ##      ###        #            ###
    ##          ###    ##     ##  ##     ##      ###       QQ#           ##Q
    ##       # ###     ##     ##  ##     ##     ## ##    QQQQQQ#       #QQQQQQ
    ##      ## ### #   ##     ##  ###   ###    ##   ##   QQQQQQQ#     #QQQQQQQ
  ############  ###   ####   ####   #### ### ##### #####   QQQQQ#######QQQQQ
(root@192.168.5.2) Password for root@ns1: masukkan password username root
Last login: Tue Oct 31 21:03:49 2023 from 192.168.5.2
FreeBSD 13.2-RELEASE releng/13.2-n254617-525ecfdad597 GENERIC

Welcome to FreeBSD!

Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories:   https://www.FreeBSD.org/security/
FreeBSD Handbook:      https://www.FreeBSD.org/handbook/
FreeBSD FAQ:           https://www.FreeBSD.org/faq/
Questions List:        https://www.FreeBSD.org/lists/questions/
FreeBSD Forums:        https://forums.FreeBSD.org/

Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with:  pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.

Show the version of FreeBSD installed:  freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages:  man man
FreeBSD directory layout:      man hier

To change this login announcement, see motd(5).
root@ns1:~ #
Dalam skrip nama pengguna Log In di atas, Anda melihat bahwa ns1 adalah nama Host server FreeBSD dan unixexplore.com adalah nama Domain server FreeBSD kami. Setelah selesai membaca artikel ini, Anda sekarang dapat terhubung menggunakan perintah ssh dan memulai sesi manajemen jarak jauh yang aman.
Subscribe on LinkedIn  Cara Mengkonfigurasi Server OpenSSH di FreeBSD

Enclosures Link: Cara Mengkonfigurasi Server OpenSSH di FreeBSD

Silahkan Berkomentar, Kakak...! Bunda...!

Posting Komentar