0

For connecting to a device via jump proxy (bastion host), I type the following:

ssh -J bhost myuser@localhost -p $PORT

myuser is the usernanme for my current logged in user on my local device as well as the account I am connecting to on the bastion host. I have more than one PORT set up.

bhost is defined in my SSH .config like this:

Host bhost
  HostName www.example.com
  PasswordAuthentication no
  IdentityFile ~/.ssh/id_ed25519

My goal is to not have to type myuser@localhost. Instead, I want to be able to login like this:

ssh -J bhost -p $PORT

No matter the bastion host or port I use, myuser@localhost is always the same, so I prefer to not have to type it.

0

2 Answers 2

0

You just need to expand on the entries in your ~/.ssh/config file. Maybe something like the following would work. You'll need to play around with it, because I feel like your question isn't really giving enough information.

.ssh\config:

# this entry is the one you're trying to ssh to
Host example
  Hostname www.example.com
  ProxyJump bhost

# this entry is the bastion (jump) host
Host bhost
  Hostname www.example.com
  Port 8022
  User myuser
  IdentityFile ~/.ssh/id_ed25519

You're really just setting up two different hosts in the .ssh/config and telling one to use the other via a ProxyJump command.

Then ssh example would be all you need to type to jump all the way through to the desired target machine.

1
  • Thanks for the ideas. The port doesn't belong to the bastion host. It is associated with the other entry.
    – MountainX
    Nov 12, 2020 at 1:20
0

Answer inspired by Tim Kennedy. As he said, this can be done via the ~/.ssh/config file.

Here is a working solution:

Host bhost
  HostName www.example.com
  PasswordAuthentication no
  IdentityFile ~/.ssh/id_ed25519

Host example1
  Hostname localhost
  User myuser
  Port 22021
  ProxyJump bhost
  PasswordAuthentication no
  IdentityFile ~/.ssh/id_ed25519

Host example2
  Hostname localhost
  User myuser
  Port 28022
  ProxyJump bhost
  PasswordAuthentication no
  IdentityFile ~/.ssh/id_ed25519

Host example3
  Hostname localhost
  User myuser
  Port 28023
  ProxyJump bhost
  PasswordAuthentication no
  IdentityFile ~/.ssh/id_ed25519

Each target device needs a unique port number. They also have a common hostname of localhost. The bastion host is an actual domain name, of course.

With this config, you can get to any of the end targets with:

ssh example1

Or

ssh exampleN

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .