---
title: 'Hopping with SSH'
url: 'https://kb.hills-family.uk/blog/hopping-with-ssh'
markdown: 'https://kb.hills-family.uk/blog/hopping-with-ssh.md'
date: '2021-05-13'
description: 'The other day, I was using ssh as a SOCK5 proxy. To recap, I needed to access a resource that was only available from a remote Linux PC (i.e. my machine → remote Linux PC → network resource). One of the network resources was an embedded device with an SSH server. Hopping to the remote Linux PC over SSH was fine, but once there, I would then need to connect to my embedded device by calling SSH again (i.e. my machine → remote Linux PC (hop 1) → embedded device (hop2)). Fortunately, this step is, in fact, unnecessary and the process can be simplified. It’s possible to create local SSH configurations within your loc'
taxonomy:
  tag:
    - Linux
    - SSH
    - netcat
    - Network
---

# Hopping with SSH

[ Home ](https://kb.hills-family.uk/)     [ Blog ](https://kb.hills-family.uk/blog)      Hopping with SSH    

   13 *May*   
#### [Hopping with SSH](https://kb.hills-family.uk/blog/hopping-with-ssh)

  [Linux](https://kb.hills-family.uk/blog/tag:Linux) [SSH](https://kb.hills-family.uk/blog/tag:SSH) [netcat](https://kb.hills-family.uk/blog/tag:netcat) [Network](https://kb.hills-family.uk/blog/tag:Network)  

The other day, I was [using `ssh` as a SOCK5 proxy](https://kb.hills-family.uk/blog/use-ssh-as-socks-5-proxy). To recap, I needed to access a resource that was only available from a remote Linux PC (i.e. my machine → remote Linux PC → network resource). One of the network resources was an embedded device with an SSH server. Hopping to the remote Linux PC over SSH was fine, but once there, I would then need to connect to my embedded device by calling SSH again (i.e. my machine → remote Linux PC (hop 1) → embedded device (hop2)). Fortunately, this step is, in fact, unnecessary and the process can be simplified.

It’s possible to create local SSH configurations within your local system by editing the file `~/.ssh/config`, creating it, if necessary. Within this file, we can use the `ProxyCommand` keyword to inform server that we wish to run a specific application once the connection is established. In this case, we can use `nc`, or *netcat*, to do the talking (remember using `nc` [when `curl` wasn’t available](https://kb.hills-family.uk/blog/when-you-dont-have-curl)?). For example:

```config
host hop_2_server_name ProxyCommand ssh hop1_user@hop1_ip nc hop_2_ip 22
```

This instruction says that the “nickname” `hop_2_server_name` will be used to `ssh` into `hop1_ip1` using `hop1_user` and then use `nc` to establish a connection to `hop_2_ip` over port `22` (SSH).

In practice, the line in my `config` file looked like:

```config
host embeddeddevice ProxyCommand ssh linuxuser@192.168.20.4 /usr/bin/nc 10.0.3.20 22
```

Save the file and head back to the command line. Assuming the user `embeddeduser` exists on the second hop — the embedded device in my case — meaning we can simply type:

```bash
ssh embeddeduser@embeddeddevice
```

You’ll then see this seamlessly and immediately connects to the second hop without any prompts from the first hop. What’s more, it uses your **local** `ssh-agent` instance for keys and will work for `ssh`, `scp` and `sftp` commands and clients.

Mike Hommey of [glandium.org](https://glandium.org) extends this concept for multiple hops. do [check it out](https://glandium.org/blog/?p=303)!

 [ Next Post](https://kb.hills-family.uk/blog/generating-multiple-lists-from-a-list-of-tuples) [Previous Post ](https://kb.hills-family.uk/blog/wireshark-for-cli)

#### Knowledge Base

Tips, tricks and how-to guides on various topics.

#### Popular Tags

  [Linux](https://kb.hills-family.uk/blog/tag:Linux) [Dynamics AX](https://kb.hills-family.uk/blog/tag:Dynamics%20AX) [D365 Finance and Operations](https://kb.hills-family.uk/blog/tag:D365%20Finance%20and%20Operations) [Network](https://kb.hills-family.uk/blog/tag:Network) [Data Management Framework](https://kb.hills-family.uk/blog/tag:Data%20Management%20Framework) [Logic Apps](https://kb.hills-family.uk/blog/tag:Logic%20Apps) [JavaScript](https://kb.hills-family.uk/blog/tag:JavaScript) [netcat](https://kb.hills-family.uk/blog/tag:netcat) [SSH](https://kb.hills-family.uk/blog/tag:SSH) [PowerShell](https://kb.hills-family.uk/blog/tag:PowerShell) [Virtual Machines](https://kb.hills-family.uk/blog/tag:Virtual%20Machines) [VMware](https://kb.hills-family.uk/blog/tag:VMware) [SQL Server](https://kb.hills-family.uk/blog/tag:SQL%20Server) [Wireshark](https://kb.hills-family.uk/blog/tag:Wireshark) [Python](https://kb.hills-family.uk/blog/tag:Python) [Licensing](https://kb.hills-family.uk/blog/tag:Licensing) [Ubuntu](https://kb.hills-family.uk/blog/tag:Ubuntu)

---

## Navigation

- Parent: [Blog](https://kb.hills-family.uk/blog.md)
- Previous: [Generating multiple lists from a list of tuples](https://kb.hills-family.uk/blog/generating-multiple-lists-from-a-list-of-tuples.md)
- Next: [Wireshark for CLI](https://kb.hills-family.uk/blog/wireshark-for-cli.md)
