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?


3 Answers 3


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 sent 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 drop (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 (use 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 instruction 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.


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.


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 [email protected]

Sample Screenshot

Hope it helps. Happy Coding Cheers!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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