Pada artikel ini, saya akan menjelaskan kepada Anda cara mengatur server SFTP menggunakan MySecureShell di Ubuntu 18.04. SFTP adalah cara aman untuk mentransfer file menggunakan koneksi SSH terenkripsi. Meskipun didukung secara luas oleh klien FTP modern, protokol ini benar-benar berbeda dari FTP (File Transfer Protocol).
Anda mungkin bertanya mengapa MySecureShell bukan server FTP tradisional. Berikut adalah beberapa fiturnya,
- Transfer data aman menggunakan SSH
- Tidak perlu mengelola sertifikat SSL
- Mudah dipasang dan dikonfigurasi
- Batasi penggunaan Bandwidth
- Pembatasan file dan folder
- Daftar Kontrol Akses menggunakan IP/Nama Pengguna/Grup/VirtualHost
- Batasi pengguna hanya memiliki sftp (akses shell dinonaktifkan secara default)
- Sistem pencatatan yang disempurnakan
Jadi mari kita mulai dengan instalasi terlebih dahulu, pengetahuan dasar tentang FTP sudah cukup untuk memahami tutorial ini.
Pemasangan
Dari ubuntu 15.04 dan di atasnya, MySecureShell tersedia di repositori default. Kami menggunakan ubuntu 18.04 untuk instalasi ini. Jalankan saja perintah di bawah ini untuk menginstal MySecureShell.
apt-get install mysecureshell
Jika tidak tersedia ikuti langkah-langkahnya, pastikan semua langkah berikut dijalankan sebagai pengguna root.
vim /etc/apt/sources.list
Tambahkan 2 baris berikut,
deb http://mysecureshell.free.fr/repository/index.php/ubuntu testing main
deb-src http://mysecureshell.free.fr/repository/index.php/ubuntu testing main
Sekarang tambahkan kunci gpg sebagai,
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys E328F22B; gpg --export E328F22B | apt-key add
gpg: keybox '/root/.gnupg/pubring.kbx' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 7601D76CE328F22B: public key "MySecureShell repository " imported
gpg: Total number processed: 1
gpg: imported: 1
OK
Setelah repositori ditambahkan, Anda dapat memulai dengan instalasi
apt-get update
apt-get install mysecureshell
Sekarang Anda semua baik untuk memulai layanan dan memeriksa statusnya
systemctl start mysecureshell.service
systemctl status mysecureshell.service
Contoh Keluaran
# systemctl start mysecureshell.service
root@li1004-153:~# systemctl status mysecureshell.service
* mysecureshell.service - LSB: MySecureShell SFTP Server
Loaded: loaded (/etc/init.d/mysecureshell; generated)
Active: active (exited) since Fri 2018-05-18 01:02:17 UTC; 4min 44s ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 2322)
CGroup: /system.slice/mysecureshell.service
May 18 01:02:17 004-153 systemd[1]: Starting LSB: MySecureShell SFTP Server...
May 18 01:02:17 004-153 mysecureshell[1314]: Starting MySecureShell SFTP Server: mysecureshell is now online with restricted features
May 18 01:02:17 004-153 mysecureshell[1314]: Note: To enable all features you have to change mysecureshell binary rights to 4755
May 18 01:02:17 004-153 systemd[1]: Started LSB: MySecureShell SFTP Server.
# systemctl status mysecureshell.service
* mysecureshell.service - LSB: MySecureShell SFTP Server
Loaded: loaded (/etc/init.d/mysecureshell; generated)
Active: active (exited) since Fri 2018-05-18 01:02:17 UTC; 50min ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 2322)
CGroup: /system.slice/mysecureshell.service
May 18 01:02:17 004-153 systemd[1]: Starting LSB: MySecureShell SFTP Server...
May 18 01:02:17 004-153 mysecureshell[1314]: Starting MySecureShell SFTP Server: mysecureshell is now online with restricted features
May 18 01:02:17 004-153 mysecureshell[1314]: Note: To enable all features you have to change mysecureshell binary rights to 4755
May 18 01:02:17 004-153 systemd[1]: Started LSB: MySecureShell SFTP Server.
#
Gunakan perintah di bawah ini untuk menghentikan dan memulai kembali layanan mysecureshell
systemctl stop mysecureshell.service
systemctl restart mysecureshell.service
Pembuatan Pengguna SFTP MySecureShell
Pertama, kita harus mencari lokasi instalasi MySecureShell,
whereis mysecureshell
Seperti yang Anda lihat pada output di bawah, jalur instalasi mysecureshell adalah /usr/bin/mysecureshell.
mysecureshell: /usr/bin/mysecureshell /usr/share/man/man8/mysecureshell.8.gz
Sekarang, setelah memverifikasi jalur, mari buat pengguna
useradd -m -s /usr/bin/mysecureshell testsftpuser
passwd testsftpuser
Seperti yang Anda lihat pada perintah di atas, kami membuat pengguna dan menetapkan jalur lokasi mysecureshell. Selain itu, Anda dapat menetapkan pengguna yang ada untuk mengakses dan menggunakan MySecureShell menggunakan perintah:
sudo usermod -s /usr/bin/mysecureshell testsftpuser
Koneksi Pengguna
Sekarang pengguna "testsftpuser" dapat terhubung ke server SFTP Anda dari klien Anda seperti yang ditunjukkan di bawah ini dengan alamat IP mesin Anda,
sftp [email protected]
IP mesin Anda
Connected to 45.33.54.153
sftp>
Selain itu, Anda dapat login ke server SFTP Anda dengan klien grafis apa pun seperti FileZilla dari sistem klien Anda.
Perintah MySecureShell
MySecureShell memiliki serangkaian perintah berikut untuk mengelola server SFTP Anda.
- sftp-admin
- sftp-kill
- sftp-state
- sftp-pengguna
- sftp-verif
- sftp-who
sftp-admin
Perintah ini memungkinkan pengelolaan MySecureShell dari jarak jauh.
sftp-admin [ssh options] user@hostname
sftp-kill
Ini akan memutuskan pengguna dari server FTP.
sftp-kill testsftpuser
Kill testsftpuser on PID 1961
(Press "Y" when requested)
sftp-state
Tampilkan status server ftp
# sftp-state
Contoh Keluaran
# sftp-state
Server is up
#
sftp-user
Perintah ini memungkinkan Anda membuat pengguna SFTP, tanpa menentukan jalur yang kita lakukan sebelumnya.
sftp-user create test
Mencantumkan pengguna SFTP
sftp-user list
test
testsftpuser
Perintah akan menghapus tes pengguna
sftp-user delete test
verifikasi sftp
Perintah ini akan memverifikasi dan memperbaiki masalah pada server MySecureShell.
sftp-verif
################################################################################
MySecureShell Verification Tool
################################################################################
### Verifing file existance ###
/bin/MySecureShell [ OK ]
/bin/sftp-who [ OK ]
/bin/sftp-kill [ OK ]
/bin/sftp-state [ OK ]
/bin/sftp-admin [ OK ]
/bin/sftp-verif [ OK ]
/bin/sftp-user [ OK ]
### Verifing rights ###
Verifing file rights of /etc/ssh/sftp_config [ OK ]
Verifing file rights of /bin/sftp-who [ OK ]
Verifing file rights of /bin/sftp-verif [ OK ]
Verifing file rights of /bin/sftp-user [ OK ]
Verifing file rights of /bin/sftp-kill [ OK ]
Verifing file rights of /bin/sftp-state [ OK ]
Verifing file rights of /bin/sftp-admin [ OK ]
Verifing file rights of /bin/MySecureShell [ OK ]
### Verifing rotation logs ###
Rotation logs have been found [ OK ]
### Verifing server status ###
Verifing server status (ONLINE) [ OK ]
[...]
sftp-who
Perintah ini akan memberitahu Anda siapa yang sedang login ke server FTP.
sftp-who
# sftp-who
--- 1 / 10 clients ---
Global used bandwidth : 0 bytes/s / 0 bytes/s
PID: 2207 Name: testsftpuser IP: pa39-178-9-194.pa.nsw.optusnet.com.au
Home: /home/testsftpuser
Status: idle Path: /
File:
Connected: 2018/05/18 01:30:50 [since 03mins 59s]
Speed: Download: 0 bytes/s [5.00 kbytes/s] Upload: 0 bytes/s [unlimited]
Total: Download: 924 bytes Upload: 100 bytes
#
Konfigurasi
File konfigurasi MySecureShell utama adalah /etc/ssh/sftp_config. Anda dapat mengonfigurasi bandwidth unggah dan unduh, pengguna chroot, jumlah maksimum koneksi, dll. dalam file konfigurasi. Anda dapat mengatur opsi ini untuk semua orang atau hanya untuk grup tertentu.
cat /etc/ssh/sftp_config
Tag bawaan
Tag default digunakan jika Anda ingin menerapkan konfigurasi untuk semua pengguna Anda
#Default rules for everybody
Default
GlobalDownload 50k #total speed download for all clients
# o -> bytes k -> kilo bytes m -> mega bytes
GlobalUpload 0 #total speed download for all clients (0 for unlimited)
Download 5k #limit speed download for each connection
Upload 0 #unlimit speed upload for each connection
StayAtHome true #limit client to his home
VirtualChroot true #fake a chroot to the home account
LimitConnection 10 #max connection for the server sftp
LimitConnectionByUser 1 #max connection for the account
LimitConnectionByIP 2 #max connection by ip for the account
Home /home/$USER #overrite home of the user but if you want you can use
# environment variable (ie: Home /home/$USER)
IdleTimeOut 5m #(in second) deconnect client is idle too long time
ResolveIP true #resolve ip to dns
LogFile /var/log/sftp-server_ftp.log
# IgnoreHidden true #treat all hidden files as if they don't exist
# DirFakeUser true #Hide real file/directory owner (just change displayed permissions)
# DirFakeGroup true #Hide real file/directory group (just change displayed permissions)
# DirFakeMode 0400 #Hide real file/directory rights (just change displayed permissions)
#Add execution right for directory if read right is set
HideNoAccess true #Hide file/directory which user has no access
# MaxOpenFilesForUser 20 #limit user to open x files on same time
# MaxWriteFilesForUser 10 #limit user to x upload on same time
# MaxReadFilesForUser 10 #limit user to x download on same time
DefaultRights 0640 0750 #Set default rights for new file and new directory
# MinimumRights 0400 0700 #Set minimum rights for files and dirs
ShowLinksAsLinks false #show links as their destinations
# ConnectionMaxLife 1d #limits connection lifetime to 1 day
# Charset "ISO-8859-15" #set charset of computer
Default
Catatan: Log tidak diaktifkan secara default, Anda dapat menentukan lokasi file log di file konfigurasi.
tag FileSpec
Tag FileSpec dibuat untuk membuat filter pada file dan direktori.
# Only check against filenames/folder names only
FileSpec
UseFullPath false
# we can use multiple deny/allow directives for clarity
Order DenyAllow
Deny ".*.exe$"
Deny ".*.sh$"
Allow all
FileSpec
Tag pengguna
Tag pengguna menentukan untuk folder beranda pengguna tertentu
User tom
Home /home/tom
User
Tag VirtualHost
Tag VirtualHost dapat mengatur batasan berdasarkan nama virtualhost
# Set home directory for this virtualhost
VirtualHost
Home /var/www/html/www.mysftpsite.com
# Set dedicated log file
LogFile /var/log/sftp/www.mysftpsite.com
# Override the maximum number of connection per user
LimitConnectionByUser 5
VirtualHost
Penginstalan gFTP
Sekarang, mari kita coba instalasi gFTP di Ubuntu 18.04 ikuti langkah-langkah di bawah ini,
sudo apt-get install gftp
- Buka gFTP dari Aplikasi
- Masukkan alamat IP server SFTP, nomor Port (Default/Ditentukan saat mengkonfigurasi server), Nama Pengguna dan Kata Sandi &gunakan SSH2. Tekan Enter untuk masuk
- Jika upaya login berhasil. Kami terhubung ke SFTP menggunakan gFTP
Itu saja untuk saat ini. Pada tahap ini, Anda akan memiliki server SFTP yang berfungsi. Semoga Anda menyukai tutorial ini dan saya telah meninggalkan beberapa bagian konfigurasi untuk Anda belajar mandiri, beri komentar tentang konfigurasi yang Anda lakukan sendiri yang membantu Komunitas Linoxide kami untuk belajar dan berkembang. Terima kasih.