I recently got a Raspberry Pi B+, and I have been playing around with it a lot. I want to start a personal project where, when I link to my Pi through an SSH connection from my laptop, I can make a "connection" light flash on my Pi's breadboard.

Essentially I would like to do something like this:

  • When there is no device SSH connected to the Pi, a constant red light appears on the breadboard.

  • When there is a SSH connection, a flashing green light will be enabled, to express that a device is connected.

I have looked online in many places for an idea on how to start something like this. I am not an expert at terminal or programming, but I think that this project will greatly help me in some of those areas. Does anyone here have experience with something like this, or can direct me in a proper direction for in which I can start? Thank you very much!

  • Basically you’re going to have to choose between a shell script or programming in something like python. Decide which you want to learn. Once you determine ssh is active and have a your script monitor for it, it’s just a matter of wiring the lights up to GPIO pins, and knowing how to turn them on and off. Do you know how to do gpio from the shell or from python?
    – T. M.
    Mar 24, 2019 at 8:02
  • @T.M. Ah, yes, I know Python. I have found some tutorials on how to use GPIO pins in Python, so I think I can figure that out. I think what I will have to learn is how to have my script monitor for a SSH connection. Thanks!
    – Charlie
    Mar 24, 2019 at 16:25
  • Hello. Just to clarify, the red light goes out and the green light starts to flash when some one connects? Or is it the same light and it needs to change colour? Would this need to work for any user or just for pi? Mar 25, 2019 at 8:54

1 Answer 1


env | grep SSH will show something like

SSH_CONNECTION=fe80::e1:5f48:ea7e:1f88%wlan0 61705 fe80::1556:be62:1604:8184%wlan0 22
SSH_CLIENT=fe80::e1:5f48:ea7e:1f88%wlan0 61705 22

This works in the ssh terminal session, you would need to test if you want to run somewhere else.

You could write a script to parse this and do whatever you want with the information.

sudo netstat -atp | grep 'ESTABLISHED'

Should show established connections.

Your Answer

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

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