Giter Site home page Giter Site logo

ttyssh's Introduction

ttyssh

ssh with tty (serial port) forwarding

Tunnel your serial port over ssh!

Usage

It's highly recommanded to setup ssh ControlMaster.

Please set baud rate locally BEFORE running ttyssh.

stty -F /dev/ttyUSB0 115200

Now launch ttyssh just as how you launch ssh:

ttyssh -t /dev/ttyUSB0 -T '$HOME/tty' <user>@<host>

You should expect a remote shell, just like a regular ssh gives you. On the remote system, you may treat $HOME/tty as a regular tty (serial port):

screen $HOME/tty

It also works with pySerial.

When the remote shell exits, the tunnel is tore down.

If you have multiple serial ports to tunnel, try:

ttyssh -t /dev/ttyUSB0 -T '$HOME/tty0' -P 23366 -p 23366 -N <user>@<host> &
ttyssh -t /dev/ttyUSB1 -T '$HOME/tty1' -P 23367 -p 23367 -N <user>@<host> &
ssh <user>@<host>
kill -s SIGINT $(jobs -p)

Notice: If you kill -s SIGKILL or kill -s SIGTERM the ttyssh process, the tunnel will keep running and cause big trouble. Do only if you know what you are doing. Refer to source code for this.

Install

ttyssh requires ssh to be available in PATH on local machine. ttyssh also depends on a tiny program socat on both local and remote machines. It's shipped by some distros. You can check if you have it by which socat. If you don't have one, choose one of the following:

  • pacman -S socat
  • apt-get install socat
  • yum install socat
  • Download source, untar, ./configure && make

After you have both ssh and socat ready, download the script from this repo:

curl -fSSL https://raw.githubusercontent.com/b1f6c1c4/ttyssh/master/ttyssh > ~/.local/bin/ttyssh && chmod +x ~/.local/bin/ttyssh

You only need to install ttyssh on your local machine.

Using ssh ControlMaster is highly encouraged. A single ttyssh will execute ssh three times so you may not want to authenticate three times. See here for more information.

Use cases

  1. Useful if we want to debug serial-port devices connected to my computer using software installed on remote machines
  2. Useful if we want to debug serial-port devices connected to remote machines using software installed on my computer
  3. Useful if we want to debug serial-port devices connected to remote machines using software installed on another remote machines

Technical details

ttyssh basically does three things:

  1. On local machine, socat /dev/ttyUSB0 tcp4-listen:localhost:23366
  2. On remote machine, socat tcp4-connect:localhost:23366 $HOME/tty
  3. On local machine, ssh -R 23366:localhost:23366 (This is ssh reverse tunnel)

Some extra code is added to ensure the links are re-established upon failure, while respond to SIGINT on the local side.

ttyssh's People

Contributors

b1f6c1c4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.