Raspberry pi usb ssh

Connect to a Raspberry Pi Zero with a USB Cable and SSH

This tutorial was updated on July 4, 2019 to reflect the latest versions of the technologies mentioned.

As some of you may know, I have a hoarding problem. I am hoarding Raspberry Pi microcomputers. In my personal collection I have one from each generation, making four standard units. Well, I recently picked up another unit, but this time a Raspberry Pi Zero. These things are about the size of a nine volt battery, but pack some serious punch. The problem is they are incredibly rare because they retail for only $5.00.

Unlike the standard Raspberry Pi units, these do not have WiFi, ethernet, or standard sized USB ports. This changes things when it comes to connecting. We’re going to take a look at getting set up with one of these Pi Zero IoT devices and be on your way towards some cool hack projects.

Like with the standard Raspberry Pi units, it takes a micro SD card with the same flavors of Linux flashed to it. You’ll note in my other tutorials, I am using Raspbian, which is a flavor of Debian Linux. I am using the same for the Raspberry Pi Zero.

Flash the Pi Zero however you see fit. If you’re using a Mac or Linux computer, you might check out my previous tutorial on the subject.

This is where things get a little different. Before we get ahead of ourselves, a lot of the material that follows will be from a set of instructions that helped me. These instructions can be found on GitHub by Andrew Mulholland.

Configuring to Emulate Ethernet Over USB

Our long term goal will be to use SSH over USB. This means that we have to configure Raspbian to treat the USB port like an ethernet port. Mount the micro SD card in a computer (not Pi Zero) and open it with Finder, or Windows Explorer, or whatever it is that you use.

The first thing that you want to do is open a file at the root of the mounted drive called config.txt. In this file you want to add the following line at the very bottom:

The above line will set us up for the next file that we alter. The next file we alter is cmdline.txt, but it is a bit different. Parameters in this file are not delimited by new lines or commas, they are delimited by space characters. In this file we want to add the following:

The above parameter should be added after the rootwait parameter. Yes the above parameter is a single parameter, meaning don’t add a bunch of space characters to it. More information on networking over USB on Linux can be found here.

By default SSH access is disabled in Raspbian. To enable SSH, create a file called ssh and save it to the root directory of the boot mount on the SD card. The file can be blank, and it has no extensions. It should exist at the same location as the other files that were edited.

At this point the micro SD can be inserted into the Pi Zero.

Connecting to the Pi Zero with USB and SSH

To connect to the Raspberry Pi Zero over USB you’ll need Bonjour or similar installed on your host computer. I’m using a Mac so I was fortunate enough to already be in the clear. For Windows you should be fine installing iTunes or QuickTime and for Linux the Avahi Daemon. Many Linux distributions should have it already installed.

Читайте также:  Анонимный блок postgresql это

With it installed, power on the Pi Zero with the USB data cable. I made sure to use the port labeled USB, not PWR. This port allows you to power the Pi Zero and do data transfer. Once connected, give it some time because it will have to configure some things for the first time.

When you feel the Pi Zero is ready, enter the following from your Mac or Linux Terminal:

If you’re using Windows you’ll have to use PuTTY or similar. Notice in my SSH command I provided the pi user? If you’re using Raspbian, it is the only user on a fresh installation. The password will be raspberry until you change it or add a new user.

You should be connected! You won’t be able to install anything or run updates because you’re not connected to the internet, but at least you have full headless Linux control. If you want to be able to access the internet from the Pi Zero without a WiFi module or similar, check out my other tutorial titled, Share Internet Between macOS and a Raspberry Pi Zero Over USB.

Conclusion

Raspberry Pi and IoT is awesome. As a long time Raspberry Pi fanatic, the Pi Zero, if you can get a hold of one, is $5.00 well spent. You get a fast IoT device at the size of a pack of gum. Since the hardware doesn’t have WiFi or BLE, we had to configure Raspbian to allow ethernet emulation over USB. Once we did this we were able to SSH into the Pi Zero as if it was somewhere on our network. A perfect jumpstart for our Internet of Things adventure.

A video version of this article can be seen below.

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in C#, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Unity. Nic writes about his development experiences related to making web and mobile development easier to understand.

Источник

Headless Pi Zero SSH Access over USB (Windows)

Published by mitch on December 14, 2019 December 14, 2019

This article covers setting up a Pi Zero or Pi Zero W for headless SSH access over USB using Windows 10. The Mac OS version of these instructions can be found here: SSH into Pi Zero over USB (Mac).

When you first get a Pi Zero the big question is — how do you access it? You can get a powered USB hub, USB keyboard, USB mouse and HDMI adapter. Or you can just plug it into your computer directly and access it over USB using ssh.

These instructions are for a Raspbian Stretch image that I downloaded from here:

I’m using the lite image (no desktop) version 4.9 from March 13, 2018. I’ve also done this with an older desktop version.

Step 1. Edit the Image

To access the Pi Zero over USB you have to edit the image first.

  • If you need to burn a new image to an SD card, download the Etcher tool from https://etcher.io
  • If you have the SD card in your Pi Zero, power it down and remove it
  • Put the SD card into an adapter and plug it into your computer
  • NOTE: Windows gets confused when you plug in a Raspbian image and it may try to get you to format it — always hit Cancel
  • In Windows 10 the SD card should appear in File Explorer as a drive named «boot»
    • If you just burned a new image using Etcher you may need to pull the SD card out and plug it back in again for File Explorer to see it
  • Open the SD card and explore the contents in File Explorer
  • You should now see the contents of the root of your Raspbian boot image

Step 2. Enable ssh

There was a security update to the Raspbian images. Now to enable ssh by default you have to place an empty filed named ssh (no extension) in the root of the card.

  • Run Notepad
  • In a new file put in one space and nothing more
  • Click File / Save As .
  • Be sure to set Save as type to All Files (so the file is NOT saved with a .txt extension)
  • Call the file ssh and save it
  • Close the file
Читайте также:  Картридж hp laserjet q2612a для каких принтеров

Step 3. Download Notepad++

Windows Notepad can’t handle the carriage returns in the Linux based files that we need to edit next. To do that you need to download a free tool called Notepad++.

  • Download Notepad++ from https://notepad-plus-plus.org
  • Install the 64-bit version.

Step 4. Edit config.txt

  • In the root folder of the SD card, open config.txt in Notepad++ (right click on the file and there should be an edit option)
  • Append this line to the bottom of that file:
  • Save the file

Step 5. Edit cmdline.txt

  • In the root folder of the SD card, open cmdline.txt in Notepad++
  • After rootwait, append this text leaving only one space between rootwait and the new text (otherwise it might not be parsed correctly):
  • If there was any text after the new text make sure that there is only one space between that text and the new text
    • Save the file

On a fresh image that has never been booted, you may see extra text after rootwait. But if you boot the pi from the disk at least once, that extra text may go away. That is why you must put the new text directly after rootwait — so it doesn’t get accidentally deleted.

Step 6. Install Bonjour

You can find Raspberry Pi’s on your network using their hostname followed by .local (example: raspberrypi.local ). But to do that in Windows you have to install the Bonjour service first.

If you have iTunes installed on Windows you probably don’t have to do this. But if you don’t, browse to:

Step 7. Boot the Pi Zero

  • Put the SD card into the Pi Zero
  • Plug a Micro-USB cable into the data/peripherals port (the one closest to the center of the board — see picture above)
    • You do NOT need to plug in external power — it will get it from your computer
  • Plug the other end into a USB port on your computer
  • Give the Pi Zero plenty of time to bootup (can take as much as 90 seconds — or more)

Step 8. Install Putty

If you already have Putty installed, skipped to the next step.

  • Browse to: https://www.putty.org
  • Download the 64-bit MSI (Windows Installer)
  • Open it to run the installer (if asked for permission, click Yes)
  • Select: Add shortcut to PuTTY on the Desktop

Step 9. Login over USB using Putty

This part assumes that ssh is enabled for your image and that the default user is pi with a password of raspberry.

  • Launch Putty
  • If this is a new image, set the Host Name (or IP address) field to raspberrypi.local (if not use your-pi-host-name.local )
  • By default the Port should be set to 22 and Connection type should be set to SSH
  • Click Open
  • If you see a Security Alert select Yes
  • A new terminal window should appear prompting you for a user name
  • For user name on a new image enter: pi
  • For a new image the default password is: raspberry

Congratulations! You can now access your Pi Zero with just a USB cable.

Step 10. Access the network

By default a pi attached to a Windows 10 machine via USB cable can’t access the network (unless the pi itself has been already setup for wireless or network access).

To allow the pi to access the network through the Windows machines, do the following:

Источник

SSH into Pi Zero over USB (7 Steps)

Published by mitch on October 10, 2020 October 10, 2020

UPDATE: This article now covers the new security change that disables ssh access by default. The Raspbian image version has also been updated.

This article covers setting up a Pi Zero for SSH USB access using a Mac. The Windows instructions can be found here: Headless Pi Zero SSH Access over USB (Windows).

When you first get a Pi Zero the big question is — how do you access it? You can get a powered USB hub, USB keyboard, USB mouse and HDMI adapter. Or you can just plug it into your computer directly and access it over USB using ssh.

Читайте также:  282012a701 картридж на эту турбину

These instructions are for a Raspbian Buster image that I downloaded from here:

I’m using the lite image (no desktop) version 4.19 from June 20, 2019. I’ve also done this with an older desktop version and Jessie Lite.

Here are my notes from walking through the process. You can find links to the original instructions in the References section below.

Step 1. Edit the image

To access the Pi Zero over USB you have to edit the image first.

  • If you have the SD card in your Pi Zero, power it down and remove it
  • Put the SD card in an adapter and plug it into your computer
  • On a Mac the SD card should appear on your desktop
  • Open the SD card icon to explore the contents

Step 2. Access the micro SD card from the command line

At a command line do the following:

You should see something like this:

The volume named boot should be the SD card with the Raspbian image on it.

You should now see the contents of the root of your Raspbian boot image.

Step 3. Enable ssh

There was a security update to the Raspbian images. Now to enable ssh by default you have to do the following:

This will write an empty file to the root of your Raspbian image. That will enable ssh on startup.

Step 4. Edit config.txt

  • In the root folder of the SD card, open config.txt ( /Volumes/boot/config.txt ) in a text editor
  • Append this line to the bottom of it:
  • Save the file

Step 5. Edit cmdline.txt

  • In the root folder of the SD card, open cmdline.txt ( /Volumes/boot/cmdline.txt ) in a text editor
  • After rootwait, append this text leaving only one space between rootwait and the new text (otherwise it might not be parsed correctly):
  • If there was any text after the new text make sure that there is only one space between that text and the new text
  • Save the file

On a fresh image that has never been booted, you may see extra text after rootwait. But if you boot the pi from the disk at least once, that extra text may go away. That is why you must put the new text directly after rootwait — so it doesn’t get accidentally deleted.

Step 6. Boot the Pi Zero

  • Put the SD card into the Pi Zero
  • Plug a Micro-USB cable into the data/peripherals port (the one closest to the center of the board — see picture above)
  • You do NOT need to plug in external power — it will get it from your computer
  • Plug the other end into a USB port on your computer
  • Give the Pi Zero plenty of time to bootup (can take as much as 90 seconds — or more)
  • You can monitor the RNDIS/Ethernet Gadget status in the System Preferences / Network panel (note that the IP address listed is not the host)

Step 7. Login over USB

This part assumes that ssh is enabled for your image and that the default user is pi with a password of raspberry.

  • Open up a terminal window
  • Run the following commands:
  • If the pi won’t respond, press Ctrl-C and try the last command again
  • If prompted with a warning just hit enter to accept the default (Yes)
  • Type in the password — by default this is raspberry

Congratulations! You can now access your Pi Zero with just a USB cable.

Here is a list of my related articles that you may find interesting:

  • Headless Pi Zero SSH Access over USB (Windows) — the version of this article that I wrote for Windows users
  • Raspberry Pi Touchscreen Kiosk Setup — in this article I show how to run a Raspberry Pi in kiosk mode, where the only thing a user sees is your Web app
  • ROS TurtleSim Beginner’s Guide (Mac) — if you are here because you’d like to get started with robotics, check out my ROS (Robot Operating System) beginner’s guide
  • Raspberry Pi Resource Guide — checkout my resource guide for links to my most popular Raspberry Pi articles, as well as useful hardware

Источник

Поделиться с друзьями
КомпСовет
Adblock
detector