Web file server linux

How to quickly set up http file sharing on GNU/Linux

If you have a good internet connexion it could be useful to be able to share files with friends via a home made solution.

We will see here how to set up a web server in order to easily share files via a http protocol on GNU/Linux.

The goal here is to do it quickly with minimal configuration.

We will use lighttpd wich is an open-source web server optimized for speed-critical environments while remaining standards-compliant, secure and flexible.

Small CPU load and low memory footprint, everything I’m looking for.

Installing lighttpd

Edit configuration file

  • Edit /etc/lighttpd/lighttpd.conf, and add this line :
  • Create upload directory :
  • Create example file :
  • Reload lighttpd service :

Connect to the web server

GNU/Linux | Lighttpd Index of

  • From your web browser connect to your newly web server (http://IP_ADDRESS/upload). From the Index of page you should see your file :

How to secure?

We have a our brand new http server but if we make it accessible from the internet (that’s what we wanted right?), everyone can potentially connect to it.

We will see here, how we can improve security.

Firewall rules

We can use the netfilter/iptables or nftables firewall to restrict access and thus allow only certain ip addresses.

Netfilter/iptables rules

root@host:~# iptables -A INPUT -p tcp —dport 80 -m state -s ALLOWED_IP —state NEW,ESTABLISHED,RELATED -j ACCEPT root@host:~# iptables -A INPUT -p tcp —dport 80 -m state —state NEW,ESTABLISHED,RELATED -j DROP

nftables rules

root@host:~# nft add rule ip filter INPUT tcp dport 80 ip saddr ALLOWED_IP ct state new,established counter accept root@host:~# nft add rule ip filter INPUT tcp dport 80 ct state new,established counter drop

Add authentication

We can also add a user/password prompt window to prevent unwanted users.

GNU/Linux | Lighttpd auth window

  • Edit /etc/lighttpd/lighttpd.conf, and add this lines :

server.modules = ( «mod_indexfile», «mod_access», «mod_alias», «mod_redirect», «mod_auth», «mod_authn_file» ) auth.backend = «plain» auth.backend.plain.userfile = «/etc/lighttpd/lighttpd-plain.user» auth.require = ( «/» => ( «method» => «basic», «realm» => «Auth», «require» => «valid-user» ) )

  • Add new user login:password :
Читайте также:  Универсальный драйвер xerox linux

root@host:~# echo «agent007:secret» > /etc/lighttpd/lighttpd-plain.user

  • Restart lighttpd service :

root@host:~# systemctl restart lighttpd.service

  • The next time someone tries to log in an authentication request will appear :

Add https support

  • Create a self signed certificate :
  • Set rights :
  • Edit /etc/lighttpd/lighttpd.conf, and add this lines :
  • Restart lighttpd service :

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Источник

How to Quickly Setup HTTP File Server in Ubuntu 20.04

There are quite a few ways to transfer files over home network. One of the easiest ways is to run a single python command in terminal.

Python contains a script that sets up simple http server. No need to install anything, and even no internet connection required.

1. Simply right-click on the folder that contains the files you want to transfer, then select ‘Open in Terminal

2. When terminal opens, run the single command:

UPDATE: You can specify the listening port (e.g., 9900) if you get “Address already in use” error, by running command:

python3 -m http.server 9900

Now any device in the same network can access the http file server by going to (change 8000 if you specified another listening port): http://server_ip:8000

In addition, you may run python3 -m http.server & instead to start the http server in background, so the terminal window can be closed.

To check your IP address, go to Settings > Wi-Fi (or Network), click on the gear button after your connected network and check the IPv4 Address.

permalink

Ji m

I’m a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to remind me outdated tutorial! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

Источник

Share Files Using Lightweight Http Servers in Linux

Lightweight server applications in Linux can be used to quickly share files between two or more devices. These web server applications are not suitable for advanced web applications that require tighter security, authentication and performance. However, they are perfectly fine if you want to use them to temporarily share files locally or remotely between multiple devices. This article will list some of these static HTTP server applications. So let’s jump in.

Читайте также:  Удаление папки линукс терминал

SimpleHTTPServer

Simple HTTP server is a built-in python module that can be used to launch a lightweight server suitable for running basic web applications and lightweight file server. As it is a built-in module, it comes pre-installed on almost all Linux distributions having Python installed by default.

Simple HTTP server serves all the files located in the folder it is run from. Run the following commands in succession to launch a simple HTTP server in the “Downloads” folder located in your home directory (commands below are for Python 3 only).

To run the server on a different port, run the following command instead (change port number according to your requirements):

You will see following terminal output on successful launch of the server:

If you click on the URL mentioned in the terminal output shown above, you will be able to see a basic file browser layout in the web browser (also on http://localhost:8000/):

To share files with a different device, you have to use a URL in the “http://ip_address:8000/” format. To find IP address of of your computer where simple HTTP server is running, run the command below:

You will get some output like this:

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8000/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened on an Android device:

To stop the server anytime, press while the terminal window is in focus.

HTTP-Server (Node.js)

Http-server is a Node.js module that allows you to run a simple, easy to use and configurable web server. You can use the http-server module to share files from any folder on your system.

To install Node.js on Ubuntu, run the command below:

To install http-server module, run the command below:

To run the http-server from “Downloads” folder in your home directory, run the following two commands in succession:

On successful launch of http-server, you will see some output like this:

You can now use the second URL listed in the output above to open the file browser in a web browser.

To stop the server anytime, press while the terminal window is in focus.

Twistd

Twistd is a simple web server that comes with the “Twisted” python module. It can be used to launch a server that uses http or ftp protocol for sharing files. To install twisted in Ubuntu, run the command below:

Читайте также:  Linux scan port nmap

To run the twistd from “Downloads” folder in your home directory, run the following two commands in succession:

On successful launch of web server, you will get some output in the terminal like this:

You can now use a URL in the “http://ip_address:8080/” format. To see IP address of your system, run the command below:

You will get some output like this:

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8080/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened in Firefox web browser on Ubuntu:

To stop the server anytime, press while the terminal window is in focus.

Httpd (Ruby)

Httpd is a lightweight server that comes with the default Ruby package on most Linux distributions. In terms of functionality, it is on par with Python’s simple HTTP server.

To install Ruby on Ubuntu, run the command below:

To run the Ruby httpd from “Downloads” folder in your home directory, run the following two commands in succession:

On successful launch of web server, you will get some output in the terminal like this:

You can now use a URL in the “http://ip_address:8000/” format. To see IP address of your system, run the command below:

You will get some output like this:

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8080/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened in Firefox web browser on Ubuntu:

To stop the server anytime, press while the terminal window is in focus.

Conclusion

These are a few lightweight web server applications that are easy to use and can be used to share files publicly. If you want to share files over a network with higher security and authentication standards, these applications may not be suitable and avoid using them in production.

About the author

Nitesh Kumar

I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.

Источник

Оцените статью
Adblock
detector