The tiniest file-sharing server. Roughly equivalent to 1e-15 ordinary file-sharing servers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
5.0 KiB

7 years ago
  1. Femtoshare
  2. ==========
  3. Ultra simple self-hosted file sharing. All files can be accessed/modified by all users. Don't upload anything secret!
  4. Quickstart: run `./femtoshare.py`, then visit `http://localhost:8000/` in your web browser.
  5. Options:
  6. $ ./femtoshare.py --help
  7. usage: femtoshare.py [-h] [--port PORT] [--public]
  8. optional arguments:
  9. -h, --help show this help message and exit
  10. --port PORT local network port to listen on
  11. --public listen on remote network interfaces (allows other hosts to see
  12. the website; otherwise only this host can see it)
  13. Rationale
  14. ---------
  15. I often need to send/receive files from untrusted computers. Google Drive can be used for receiving, but not sending - I don't care about people seeing the files, but I do care about not revealing my account credentials when logging in to upload files.
  16. Services like WeTransfer work for sending, but they often have tiny file size limits and long, hard-to-type file URLs, if they work at all.
  17. I made Femtoshare to fix these issues. It's basically an FTP server that only needs a web browser to browse/download/upload. No file size limits and easily-memorized links, plus no worries about revealing important account credentials! A site-wide password is easily added to keep out the most unsophisticated attackers.
  18. Deployment
  19. ----------
  20. Minimal public-facing deployment: `./femtoshare.py --port 1234 --public` is visible at `http://YOUR_HOST:1234`.
  21. For improved security, authentication, and HTTPS support, we can run the script as a systemd daemon and put it behind an Nginx reverse proxy, configured to use HTTP Basic Authentication. Assuming a fresh Ubuntu 16.04 LTS machine:
  22. 1. SSH into the machine: `ssh ubuntu@ec2-35-166-68-253.us-west-2.compute.amazonaws.com`.
  23. 2. Run software updates: `sudo apt-get update && sudo apt-get upgrade`.
  24. 3. Harden SSH: in `/etc/ssh/sshd_config`, change `PasswordAuthentication` to `no` and `PermitRootLogin` to `no` and `AllowUsers` to `ubuntu`. Restart `sshd` using `sudo service sshd restart`.
  25. 4. Get requirements: `sudo apt-get nginx openssl`.
  26. 5. Get the code: `sudo mkdir -p /var/www/femtoshare && cd /var/www/femtoshare && sudo wget https://raw.githubusercontent.com/Uberi/femtoshare/master/femtoshare.py`.
  27. 6. Set up restricted user: `sudo adduser --system --no-create-home --disabled-login --group femtoshare` (there is a `nobody` user, but it's better to have our own user in case other daemons also use `nobody`).
  28. 7. Set up file storage directory: `sudo install -o femtoshare -g femtoshare -d /var/www/femtoshare/files`.
  29. 8. Set up systemd service to start Femtoshare on boot:
  30. ```bash
  31. sudo tee /lib/systemd/system/femtoshare.service << EOF
  32. [Unit]
  33. Description=Femtoshare
  34. [Service]
  35. Type=simple
  36. PrivateTmp=yes
  37. User=femtoshare
  38. Group=femtoshare
  39. ExecStart=/var/www/femtoshare/femtoshare.py
  40. Restart=always
  41. RestartSec=5
  42. [Install]
  43. WantedBy=multi-user.target
  44. EOF
  45. sudo systemctl daemon-reload
  46. sudo systemctl enable femtoshare.service
  47. ```
  48. 9. Set up a password file for HTTP Basic Authentication: `echo "user:$(openssl passwd -apr1 -salt 8b80ef96d09ffd0be0daa1202f55bb09 'YOUR_PASSWORD_HERE')" | sudo tee /var/www/femtoshare/.htpasswd`
  49. 10. Set up Nginx as a reverse proxy with HTTP Basic Authentication:
  50. ```bash
  51. sudo tee /etc/nginx/conf.d/femtoshare.conf << EOF
  52. server {
  53. listen 80;
  54. server_name ~.;
  55. # HTTP Basic Authentication
  56. auth_basic "Log in with username 'user' to access files";
  57. auth_basic_user_file /var/www/femtoshare/.htpasswd;
  58. # serve directory listing
  59. location = / {
  60. proxy_pass http://127.0.0.1:8000;
  61. client_max_body_size 1000M;
  62. }
  63. # serve uploaded file
  64. location ~ /.+ {
  65. root /var/www/femtoshare/files;
  66. }
  67. }
  68. EOF
  69. ```
  70. 11. Set up HTTPS with Let's Encrypt: `export LC_ALL="en_US.UTF-8"; export LC_CTYPE="en_US.UTF-8"; sudo wget https://dl.eff.org/certbot-auto && sudo chmod a+x certbot-auto && sudo ./certbot-auto --nginx --debug`
  71. 12. Set up twice-daily certificate renewal cronjob with Let's Encrypt: add `23 0,12 * * * PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin /var/www/femtoshare/certbot-auto renew >> /var/www/femtoshare/letsencrypt-renew-certificate.log 2>&1` in the root crontab with `sudo crontab -e` (setting `PATH` is necessary in order to get Nginx config updates to work).
  72. 13. Start Femtoshare and Nginx: `sudo systemctl start femtoshare.service` and `sudo service nginx restart`.
  73. 14. Allow incoming and outgoing HTTP and HTTPS traffic through the firewall.
  74. License
  75. -------
  76. Copyright 2018-2018 [Anthony Zhang (Uberi)](http://anthonyz.ca).
  77. The source code is available online at [GitHub](https://github.com/Uberi/femtoshare).
  78. This program is made available under the MIT license. See ``LICENSE.txt`` in the project's root directory for more information.