GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come configurare il server SFTP MySecureShell su Ubuntu 18.04

In questo articolo, ti spiegherò come configurare un server SFTP utilizzando MySecureShell su Ubuntu 18.04. SFTP è un modo sicuro per trasferire file utilizzando una connessione SSH crittografata. Sebbene sia ampiamente supportato dai moderni client FTP, è un protocollo completamente diverso dall'FTP (File Transfer Protocol).

Potresti chiedermi perché MySecureShell invece del tradizionale server FTP. Ecco le poche funzionalità,

  • Trasferimento sicuro dei dati tramite SSH
  • Non è necessario gestire i certificati SSL
  • Facile da installare e configurare
  • Limita l'utilizzo della larghezza di banda
  • Restrizioni di file e cartelle
  • Elenco controllo accessi tramite IP/Nome utente/Gruppi/VirtualHost
  • Limita agli utenti di avere solo sftp (l'accesso alla shell è disabilitato per impostazione predefinita)
  • Sistema di registrazione avanzato

Quindi iniziamo prima con l'installazione, la conoscenza di base di FTP è sufficiente per comprendere questo tutorial.

Installazione

Da Ubuntu 15.04 e versioni successive MySecureShell è disponibile nei repository predefiniti. Stiamo usando Ubuntu 18.04 per questa installazione. Basta eseguire i comandi seguenti per installare MySecureShell.

apt-get install mysecureshell

Se non disponibile, segui i passaggi, assicurati che tutti i passaggi seguenti vengano eseguiti come utente root.

vim /etc/apt/sources.list

Aggiungi le seguenti 2 righe,

deb http://mysecureshell.free.fr/repository/index.php/ubuntu testing main
deb-src http://mysecureshell.free.fr/repository/index.php/ubuntu testing main

Ora aggiungi la chiave gpg come,

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

Una volta aggiunto il repository, puoi iniziare con l'installazione

apt-get update
apt-get install mysecureshell

Ora sei a posto per avviare il servizio e verificarne lo stato

systemctl start mysecureshell.service
systemctl status mysecureshell.service

Esempio di output

# 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.
#

Utilizzare i comandi seguenti per arrestare e riavviare il servizio mysecureshell

systemctl stop mysecureshell.service
systemctl restart mysecureshell.service

Creazione utente SFTP MySecureShell

Innanzitutto, dobbiamo trovare la posizione di installazione di MySecureShell,

whereis mysecureshell

Come puoi vedere nell'output di seguito, il percorso di installazione di mysecureshell è /usr/bin/mysecureshell.

mysecureshell: /usr/bin/mysecureshell /usr/share/man/man8/mysecureshell.8.gz

Ora, dopo aver verificato il percorso, creiamo un utente

useradd -m -s /usr/bin/mysecureshell testsftpuser
passwd testsftpuser

Come vedi nel comando sopra, stiamo creando un utente e assegnando il percorso della posizione di mysecureshell. Inoltre, puoi assegnare agli utenti esistenti l'accesso e l'utilizzo di MySecureShell utilizzando il comando:

sudo usermod -s /usr/bin/mysecureshell testsftpuser

Connessione utente

Ora l'utente "testsftpuser" può connettersi al tuo server SFTP dai tuoi client come mostrato di seguito con l'indirizzo IP della tua macchina,

sftp [email protected]

IP della tua macchina

Connected to 45.33.54.153
sftp>

Inoltre, puoi accedere al tuo server SFTP con qualsiasi client grafico come FileZilla dal tuo sistema client.

Comandi di MySecureShell

MySecureShell ha il seguente set di comandi per amministrare il tuo server SFTP.

  • sftp-admin
  • sftp-kill
  • stato sftp
  • utente sftp
  • sftp-verif
  • sftp-chi

sftp-admin

Questo comando permette di gestire un MySecureShell da remoto.

sftp-admin [ssh options] user@hostname

sftp-kill

Disconnetterà l'utente dal server FTP.

sftp-kill testsftpuser
Kill testsftpuser on PID 1961
(Press "Y" when requested)

stato sftp

Mostra lo stato del server ftp

# sftp-state

Esempio di output

# sftp-state
Server is up
#

utente sftp

Questo comando ti permette di creare un utente SFTP, senza specificare il percorso che abbiamo fatto prima.

sftp-user create test

Elenca gli utenti SFTP

sftp-user list
test
testsftpuser

Il comando eliminerà il test utente

sftp-user delete test

sftp-verif

Questo comando verificherà e correggerà i problemi su un 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-chi

Questo comando ti dirà chi è attualmente connesso al 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
#

Configurazione

Il file di configurazione principale di MySecureShell è /etc/ssh/sftp_config. Puoi configurare la larghezza di banda di upload e download, gli utenti chroot, la quantità massima di connessioni ecc. Nel file di configurazione. Puoi impostare queste opzioni per tutti o solo per un gruppo particolare.

cat /etc/ssh/sftp_config

Tag predefinito

Il tag predefinito viene utilizzato se desideri applicare una configurazione per tutti i tuoi utenti

#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

Nota: I registri non sono abilitati per impostazione predefinita, puoi definire la posizione del file di registro nel file di configurazione.

Tag FileSpec

Il tag FileSpec è creato per creare filtri su file e directory.

    # 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 utente
Il tag utente definisce per una cartella home utente specifica

User tom 
Home /home/tom 
User

Tag VirtualHost

Il tag VirtualHost può impostare limitazioni in base al nome di 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

Installazione gFTP

Ora, proviamo l'installazione di gFTP su Ubuntu 18.04, segui i passaggi seguenti,

sudo apt-get install gftp
  • Apri gFTP dalle applicazioni
  • Inserire l'indirizzo IP del server SFTP, il numero di porta (predefinito/specificato durante la configurazione del server), il nome utente e la password e utilizzare SSH2. Premi Invio per accedere
  • Se il tentativo di accesso ha esito positivo. Siamo collegati a SFTP tramite gFTP

È tutto per ora. A questo punto, avrai un server SFTP funzionante. Spero che questo tutorial ti piaccia e che ho lasciato alcune parti di configurazione per te per l'autoapprendimento, commenta gentilmente la configurazione che hai fatto per te stesso che aiuta la nostra comunità di Linoxide ad imparare e crescere. Grazie.


Ubuntu
  1. Come configurare il server SFTP su Ubuntu 20.04 Focal Fossa Linux

  2. Come configurare il server Rsyslog su Ubuntu 18.04 LTS

  3. Come configurare Zimbra Mail Server su Ubuntu 16

  4. Come configurare il server NTP su Ubuntu e LinuxMint

  5. Imposta il server Rsyslog su Ubuntu 20.04 - Come farlo?

Come configurare il server multiplayer di Minecraft su Ubuntu 16.04

Come configurare OpenVPN su Ubuntu Server

Come configurare Git Server su Ubuntu 20.04

Come configurare il server Rsyslog su Ubuntu

Come configurare il server DHCP su Ubuntu

Come installare OmniDB Server su Ubuntu 20.04