apt install -y nbd-server nbd-client apache2 wget samba smbclient cifs-utils tftpd-hpa tftp
export LOCAL_IP="192.168.21.2"
- Enable SSL module and restart the server
a2enmod ssl
a2ensite default-ssl
systemctl restart apache2
- Create a file to share. I am just creating a disk file to reuse it in NBD server. You can create any type of file.
dd if=/dev/zero of=/var/www/html/disk0 bs=1M count=100
chmod a+w /var/www/html/disk0
mke2fs /var/www/html/disk0
- Access the file via HTTPS server
wget --no-check-certificate https://${LOCAL_IP}/disk0
- Start hosting the disk image created above.
nbd-server ${LOCAL_IP}:10809 /var/www/html/disk0
- Access the disk image via NBD server
nbd-client ${LOCAL_IP} 10809 /dev/nbd0
- Mount, use & unmount NBD disk
mount /dev/nbd0 /mnt
ls /mnt
umount /mnt
- Disconnect the client after we are done with the disk
nbd-client -d /dev/nbd0
- Add a share named "users" to server configuration
cat <<"EOF" >> /etc/samba/smb.conf [users] path = /var/www/html browseable = yes read only = no force create mode = 0660 force directory mode = 2770 guest ok = no #valid users = nbd @nbd @sambashare EOF
- Add & enable a user
smbpasswd -a nbd
smbpasswd -e nbd
- Restart services
systemctl restart smbd
systemctl restart nmbd
- Verify the server
smbclient //${LOCAL_IP}/users -U nbd
- Mount samba share locally
mount -t cifs -o username=nbd -o nolock,sec=ntlmsspi,seal,vers=3.0,rw //${LOCAL_IP}/users /mnt
- Use and unmount
ls /mnt
umount /mnt
- Update server configuration
cat <<"EOF" > /etc/default/tftpd-hpa TFTP_USERNAME="nbd" TFTP_DIRECTORY="/var/www/html" TFTP_ADDRESS=":69" TFTP_OPTIONS="--secure" EOF
- Restart service
systemctl restart tftpd-hpa
- Get a file from the server
tftp ${LOCAL_IP}
-
tftp> get disk0
-
tftp> quit
- Get a file from the server using busybox
busybox tftp -g -r disk0 ${LOCAL_IP}