1

I have set up my new Pi Zero (not the pi zero W), to be 'headless' - so I can plug it in to my PC via USB and SSH directly into it, without a monitor or internet connection.

I was wandering how I could make it so that it plugs into my PC and I can open it's IP address in my browser and view an HTML file, like a normal website.

I wasn't sure what this is called so was unable to look it up.

Any help would be great - Sam.

  • You can use rsync to transfer files over an ssh connection... – scitronboy Mar 6 at 19:08
  • 2
    Install a http server (nginx, apache, lighttpd) ... you should then be able to just open http://raspberrypi.local in your PC when the pi is connected – Jaromanda X Mar 6 at 22:14
  • @JaromandaX That's what I described in my answer. – scitronboy Mar 6 at 23:30
  • @scitronboy - absolutely not ... plugin and browse is what OP wants ... plugin, ssh, cd, run python, browse is what your answer does ... and god knows why you even mention rsync – Jaromanda X Mar 6 at 23:41
  • Please note that marking an answer as accepted is all that is required to show a question is solved. There is no need to put "solved" in the title or add parts of the answer as an edit to the question. Thanks. – Ghanima Mar 7 at 20:17
-3

You can use rsync to transfer files over an ssh connection.

Or, If you want to actually serve the file over your local network, try this (as described in this answer):

Change into the directory where your file is, then rename it index.html and run this command:

sudo python3 -m http.server

That will create a simple HTTP server that serves the web page over the pi's private ip address. Then you can access it in your browser by going to http://192.168.0.x:8000. Replace 192.168.0.x with your own pis unique private IP. You can find your pi's ip address with the command hostname -I.

You can easily automate this. For example:

Create a shell script named /home/pi/run_web_server.sh on your pi. Add the following to the script:

cd path/to/directory/where/html/file/stored
cp file_name.html index.html
sudo python3 -m http.server

Then, the easiest way to run the script on startup would be to modify the rc.local file with sudo nano /etc/rc.local and then add the following to the bottom of the file. before the exit 0:

sudo /home/pi/run_web_server.sh

Then, after the pi boots, it will start a web server which will serve the HTML file to http://pi.ip.address:8000

Please note that rc.local is not an old and not very good way of automating stuff on startup. However it is the easiest way.

  • You can use rsync ... not for browsing - why would OP need to "rename" a file, if the question states view an HTML file, like a normal website - it's already an HTML file – Jaromanda X Mar 6 at 22:20
  • @JaromandaX In some cases, using rsync to transfer the HTML file to the computer with a browser would work just fine. I said to rename the file to index.html because if it is named index.html then the python http server will serve it to the root of the website; instead of http://pi:8000/file.html. What's wrong with my answer??? – scitronboy Mar 6 at 23:34
  • OP wants to plugs into my PC and I can open it's IP address in my browser ... what your answer would require is: 1 - ssh into the pi 2 - navigate to some folder 3 - start a python3 web server so that you can finally browse the folders contents from the PC – Jaromanda X Mar 6 at 23:40
  • @JaromandaX I edited my answer. – scitronboy Mar 6 at 23:55
  • whats right with it? – Jaromanda X Mar 7 at 2:26
-3

There are two issues here... the first is "what" do you want to do (have access to files) and the second is "how" do you want to solve it?

You've presupposed an answer such as "plug into the PC via USB" ... which isn't an approach I would use.

While you could actually install a web server, it sounds like you really just want remote access to the filesystem. In that case, skip the web server idea.

If you have not done so already, enable the ssh (secure shell) service on your Pi. Older OS versions enabled this by default. Newer Raspbian Stretch OSes disable it by default but it is easy to enable. Just run sudo raspi-config (this opens a configuration interface). Choose "Interfacing Options" (probably item #5 on the first menu). Next choose "SSH" (probably the 2nd menu option). Select "Yes" as the answer to "Would you like the SSH server to be enabled?". Acknowledge all prompts and it will return you to the main menu. Then tab over to "Finish" to exit rasps-config.

That's it! You're basically done (but probably confused). The "ssh" (secure shell normally used for remote terminal access via a utility such as PuTTY on Windows (any Unix/Linux box would have an "ssh" command line and doesn't need a utility like PuTTY)) also can do secure file transfer protocol (sftp).

Now you need a client on your Windows PC. Filezilla is free and probably the most popular client. I use a commercial (non-free) client. Any client that supports "sftp" will work. Just provide the hostname (or IP address), the username (e.g. the "pi" user or any other user you created) and appropriate password.

The client will give you a file-browser interface showing both your local side (PC) and remote side (the Pi) and you can drag files across at will (just like you can in Windows Explorer, etc.) Some of these utilities support treating the "sftp" connection as if it is a remote disk ... which means you can edit the files as well.

(Note that FileZilla will want to default to "ftp" and not "sftp" but it does support "sftp"). "ftp" is insecure (everything is transferred in-the-clear over networks ... including usernames & passwords) and its rare to find hosts that have the service enabled (or even installed). Make sure you configure your client to use "sftp").

There are slightly more complicated options such as installing a Samba server on the Pi which allows Windows PCs to mount any filesystems that you make available via Samba. See: https://www.raspberrypi.org/documentation/remote-access/samba.md (or just do a web search on installing samba ... you'll find loads of articles and videos).

  • 2
    Have you read the question? OP WANTS to plug pi into computer, and the first thing you say "I wouldn't do it like that" and suggest using SSH ... erm, it's a pi 0 ... please explain how you SSH to a pi 0 without plugging it in to a computer or adding a network dongle to it – Jaromanda X Mar 6 at 22:16
  • Most computer USB ports only work in "host" mode and don't support "guest" mode. USB 3 supports this but Pi doesn't have USB 3. That leaves you with needing a usb serial UART (possibly two of them) and a null-modem adapter. (At which point you can use modem serial modem software like zmodem, etc.) That would let you transfer files ... but it's a klunky solution. Considering that a Pi Zero W can be had for $5 (list price is merely $10), trying to buy special cables and adapters will likely cost more than just replacing the Pi Zero with a PI Zero W (cheaper and much better). – Tim Campbell Mar 7 at 2:10
  • Tim, you clearly know zero about the pi zero's so called "gadget" modes - which, clearly, the OP DOES know about since he is SSHing into a Pi Zero and states NOT Zero W – Jaromanda X Mar 7 at 2:11
  • Thanks @TimCampbell - but I suppose it was a web server I was after, not FTP - but I very much appreciate your help. – SBerry Mar 7 at 13:58
  • Do you already have a web-server running? I the question really about how to find the IP address of the server? If so, open a cmd window on the PC, use "ipconfig" to list all the network interfaces and find the network that connects to the Pi. Note the "broadcast" IP address. Use "ping <broadcast IP>". This asks every device on the network (including the PC itself) to echo the ping packet and you'll see the IP address of every attached device (but there is only one other device besides your PC). That "other" IP address is the Pi. Is that what you were really after? – Tim Campbell Mar 7 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.