-1

I am trying to create a script on my computer that will ssh into my raspberry pi and automatically configure some wifi options (over usb->serial cable, with screen). I am running into issues getting ssh to give the raspberry pi it's password when it asks for it.

I tried in my .sh file: screen /dev/cu.usbserial 115200 pi raspberry cd Desktop

This opens screen, but then I have to press enter and give the pi its password and login manually. Is there any way I can configure my .sh file to give the pi it's login and password?

Emmett P
  • 177
  • 2
  • 6
  • 2
    configure passwordless login with an SSH keypair (without a passpharase to protect the key). for windows https://raspberrypise.tumblr.com/post/148032481829/ssh-security-and-usability-part-1 for linux/mac https://raspberrypise.tumblr.com/post/148401541394/ssh-security-and-usability-part-2 remember don't add a passphrase to your key. This does create a security risk and should be used only for this script all other ssh should use a passphrase protected key. You may also want to checkout fabric http://www.fabfile.org/ – Steve Robillard Sep 13 '16 at 19:05

3 Answers3

1

SSH does not run on the serial port, it runs a getty directly. You can interact with it in any program that can talk to a serial device like using pyserial with python. Using this, you can open a serial connection and send it the characters you would normally type to interact with the getty. You can read and parse responses as well to make it less error prone.

But, this is just scripting an interactive prompt, it is not the most reliable way to set up a Pi. For example, if a character gets dropped (which can happen on a serial line) then it can mess up the commands you are trying to enter.

If you are on, or have, a Linux system available (you can use VirtualBox and Vagrant to easily create one), it is better to chroot into the image and set it up from your main PC. See this guide for more detailed instructions on how to do this with the archlinuxarm image, though the steps are similar for Raspbian (mostly you can skip to the chroot steps). Also, this guide for a more detailed explication of creating the chroot.

Michael Daffin
  • 761
  • 1
  • 5
  • 10
1

The simplest way (without the need to install any additional stuff) to accomplish this, is to use ssh keys.

On your machine where you are running from run ssh-keygen and take all the default answers. On your Raspberry, run the same thing. This will create and populate a directory ~/.ssh with correct permissions.

Once you have that, you need to copy the contents of ~/.ssh/id_rsa.pub from your source computer to ~/.ssh/authorized_keys on your Pi.

After that you are good to go - no password needed.

SiKing
  • 347
  • 2
  • 12
0

You can use the sshpass utility to login to the raspberry pi.

  • You can install the sshpass using $sudo apt-get install sshpass
  • Then you can add the following line to your script for automated login to raspberry pi sshpass -p "password" ssh username@hostname
  • For example - sshpass -p raspberry ssh pi@192.168.1.1

Sample Screenshot

Hope it helps. Happy Coding Cheers!!

Tanuj
  • 246
  • 2
  • 4