Accessing Remote Servers with SSH ProxyJump and Jump Hosts


Updated on Nov 11, 2024
· 12 mins read
networking security ssh engineering

Introduction

In practice, it is often impossible to establish a direct SSH connection with a remote server because of different network segmentation policies, firewall limitations, or extremely strict security measures at the organisation’s end. This is where Jump Hosts, commonly referred to as bastion hosts, fill the gap by providing means to connect two or more network segments. Together with SSH’s ProxyJump feature, they offer a secure way to connect to servers that otherwise cannot be reached. This guide dives into SSH ProxyJump and Jump Hosts, providing practical tips and configurations to maximise their effectiveness.

thumbnail

Summary

  • If you have a server jump_host where you can SSH directly, and another server target_host where you can SSH from jump_host, then you can directly access target_host using the command:

    ssh -J username@jump_host username@target_host
    

    Replace jump_host and target_host with their IP addresses or domain names. Also set the username appropriately.

Understanding SSH and Its Importance

SSH, or Secure Shell, is a protocol designed to secure data transmission over unsecured networks. It enables remote login, command execution, and secure file transfers (via SFTP and SCP) through encrypted communication, ensuring data protection against interception and unauthorized access.

Core Features of SSH:

  • Encryption: Protects data from interception and man-in-the-middle attacks.
  • Authentication: Confirms the identities of clients and servers using passwords, public keys, or certificates.
  • Integrity : Ensures data hasn’t been tampered with using cryptographic hash functions.
  • Port Forwarding: Allows secure tunneling of network services.

SSH is crucial for securely replacing outdated, insecure protocols like Telnet, ensuring privacy and compliance with security standards—especially essential for organizations managing sensitive data.

What is a Jump Host?

A Jump Host is an agnostic intermediate system in which network traffic is switched to access the target servers from a different security domain or logical network layer. This is a controlled gateway through which the external networks can access some servers that are otherwise not directly recognisable from the external network by other users, such as the administrators and other accredited users.

JumpHosts

Why Use a Jump Host?

  • Enhanced Security : Secures the access through one point but makes it stronger and easier to monitor as compared to other options.
  • Network Segmentation: Connects separate network sectors with one another without enabling direct access to sensitive internal hosts in external networks.
  • Compliance and Auditing: Helps in offering an easy access channel that can always be examined for any malicious incidences.
  • Reduced Risk: Reduces the risk of compromise of a site by placing most important and sensitive systems behind a more secure middle tier.

What is SSH ProxyJump

In the past, Previously, when using a Jump Host, it was necessary to first establish an SSH connection to the Jump Host and then initiate another SSH connection to the target server. This process was often tedious and inefficient, causing frustration for many users. Prior to the introduction of ProxyJump, there was no simple way to specify one or more Jump Hosts in the SSH connection process, requiring complex configurations such as local port forwarding. However, with the release of OpenSSH 7.3, the ProxyJump option was introduced, allowing users to easily specify Jump Hosts directly in the SSH command or configuration file, streamlining the connection process.  Learn more about ProxyJump in the OpenSSH release notes for version 7.3 .

SSH ProxyJump

Basic Syntax:

ssh -J [user@]jump_host[:port] target_host

Advantages of Using ProxyJump:

  • Simplicity: Saves time as compared to having to type more than one command about SSH or has to make specific configurations when the port forwarding is getting used.
  • Efficiency: Connects to a single system and creates an end-to-end encrypted channel over a single TCP port thus saving latency and resources.
  • Flexibility: Allows for cascading multiple Jump Hosts suitable for complex network structures.
  • Seamless Integration: Interacts with ssh settings and has many other useful features such as forwarding of ssh agent, tcp port forwarding and X11.

Practical Examples

1. Single Jump Host Access

To access server.destination.com through jump.example.com, use the following command:

ssh -J user@jump.example.com user@server.destination.com
Single Jump Host Access Terminal Pic

This command tells SSH to first connect to jump.example.com as user and then connect to server.destination.com as user.

2. Multiple Jump Hosts (Chained Access)

In complex environments, you may need to hop through multiple Jump Hosts to reach your target server. For example:

ssh -J user@jump1.example.com,user@jump2.example.com user@server.destination.com

This command chains two Jump Hosts, jump1.example.com and jump2.example.com, before accessing the target server.

3. SSH Config File for Convenience

Typing these command’s every time can prove quite cumbersome, it is therefore for convenience that you can set up your SSH client by making entries in the ~/.ssh/config file.

Host jump-host
    HostName jump.example.com
    User user

Host host_destination 
    HostName server.destination.com
    User user
    ProxyJump jump-host
SSH Config Terminal Pic

With this configuration, you can connect to the destination server using:

ssh host_destination 
SSH Host destination Command Terminal Pic

4. SSH Tunnel Using Jump Host

As mentioned earlier when connecting through the Jump Host you can use SSH port forwarding if you try to connect directly to the port number of the target server you will not be granted access due to the TCP port forwarding.

ssh -J user@jump.example.com -L 8080:remote_service:80: user: destination_server.hostname

This command forwards your local port 8080 to remote_service:80 on server.destination.com, allowing access to the remote service through localhost:8080 on your machine.

Using SSH Keys to Avoid Entering Passwords Every Time

Among the benefits of the SSH, there is a possibility to use the key-based authentication. By utilizing ssh keys, you have the ability to log into your servers without entering a password every time, which not only enhances convenience but also security.

Generating SSH Keys

To generate an SSH key pair, use the following command:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

As the next steps, hit enter to save the key pair under the default paths (~/.ssh/id_rsa and ~/.ssh/id_rsa.pub) then set a passphrase if needed. Refer to the OpenSSH key generation documentation for more details.

Copying Your Public Key to the Server

Use the ssh-copy-id command to copy your public key to the remote server:

ssh-copy-id user@server.destination.com

This adds your public key to the ~/.ssh/authorized_keys file on the server and allowing you to authenticate without a password.

Using SSH Keys with Jump Hosts

When connecting through a Jump Host, ensure that your SSH keys are set up on both the Jump Host and the target server.

Copy your key to the Jump Host:

ssh-copy-id user@jump.example.com

Then, from the Jump Host, copy your key to the target server:

ssh user@jump.example.com
ssh-copy-id user@server.destination.com

Alternatively, you can copy your public key directly to the target server using:

ssh -J user@jump.example.com user@server.destination .com 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub

SSH Agent Forwarding

If you cannot copy your SSH key to the target server, you can use SSH agent forwarding. This allows you to authenticate to the target server using your local SSH keys.

Add the following to your SSH configuration:

Host *
    ForwardAgent yes

Note that SSH agent forwarding should be used with caution, as it can be a security risk if the Jump Host is compromised.

Using ProxyCommand to Jump Host

Although ProxyJump simplifies the process of connecting through a Jump Host, there are scenarios where using ProxyCommand is preferable, especially in environments that require custom proxy settings or non-SSH proxies.

Using ProxyCommand in SSH Config

You can set up ProxyCommand in your ~/.ssh/config file:

Host host_destination 
    HostName server.destination.com
    User user
    ProxyCommand ssh -W %h:%p user@jump.example.com

This configuration instructs SSH to connect another SSH session at jump.example.com and then channel on to the target server.

Advantages of ProxyCommand

  • Flexibility : May be used to process non SSH proxies or any other proxies that may be required in handling proxies.
  • Compatibility: It comes in handy where ProxyJump is not feasible because the server has outdated SSH servers.
  • Customizability: Permits even more configurations like netcat or other scripts unlike simple hand URL injections.

Security Best Practices

While, the usage of Jump Hosts and ProxyJump make it easier to work, one needs to make sure that the network and systems are secure enough.

1. Harden the Jump Host:

  • Minimal Services: Only have the indispensable software on the machine and turn off other services to minimize the chances the machine will be attacked.
  • Regular Updates: The latest updates with security fixes should apply to the operating system as well as all installed software.
  • Firewall Configuration: Put stringent rules for connection security to and from the Jump Host to only allow the necessary traffic.
  • Intrusion Prevention Systems (IPS): Use IPS solutions to ensure that the organization gets rid of malicious activities.

2. Strong Authentication Mechanisms:

  • SSH Key Authentication: Public key authentication must be used and it is recommended that password authentication be turned off because an attacker can attempt to guess a user’s password and gain access to the system.
  • Multi-Factor Authentication (MFA): Reduce the number of password reset requests by enforcing MFA to provide second and in some cases third form of identification.
  • Authorized Keys Management: This means that people should audit and manage those keys that are allowed in the operating system to avoid having unauthorized keys being accepted by the operating system.

3. Access Control:

  • Principle of Least Privilege: Users should be given just the basic level of permissions required by their functions in the application and should not be provided with administrative permission when not required.
  • Role-Based Access Control (RBAC): Use RBAC in order to organize permissions belonging to roles that are or might be applied in the organization.
  • User Account Management: Daily monitor user accounts and check which of these accounts can now be deleted or deactivated since they are no longer useful.

4. Monitoring and Logging:

  • Comprehensive Logging: Allow comprehensive recording of all the ssh sessions; regular login attempts, successful or failed login attempts, commands issued and file transfers made.
  • Centralized Log Management: For the Jump Host and other strategic systems, integration of a centralized logging server will be useful in compilation of logs.
  • Security Information and Event Management (SIEM): Use SIEM tools to analyze events occurring in the network looking for peculiarities that may indicate an issue. Learn more about Security Information and Event Management (SIEM).

Applying use cases in an application development scenarios

1. Enterprise Network Management:

Large organizations are usually characterized by a highly complex topology and numerous security perimeters. These zones are tenanted by Jump Hosts which administrators use to access servers safely in the zones, preventing risking the highly sensitive items to the networks which may be relatively insecure.

2. Cloud Environments:

Originally in cloud environment like AWS, Azure or Google Cloud, to gain access to instances located in the private subnets, the usage of the bastion hosts or Jump Hosts was well-marked. They offer a gateway to the instant without exposing all the instances to the internet.

3. Remote Support and Maintenance:

Through a Jump Host, external vendors or support teams can be given right of entry so that essential maintenance jobs can be done without direct contact with inner resources. Such access can be well regulated and supervised.

4. Compliance with Security Standards:

Some standards like PCI DSS, HIPAA, and the GDPR necessitate the use of secure access and logging; Jump Hosts meet these needs in industries comprising finance, pharmaceutical, and tech.

Troubleshooting Common Issues

1. Connection Timeouts:

  • Network Reachability: Ensure that both the Jump Host and the target server are network accessible. Do not use unpredictable names, only ping and traceroute for diagnosis of the network connectivity problems.
  • Firewall Rules: Ensure firewalls on all the intermediate devices allow connection to the required ports for traffic SSH.
  • DNS Resolution: Check that all hostnames are responding to requests on the correct port number. If needed, resolve them to IP addresses, or convert your /etc/hosts file.

2. Authentication Failures:

  • SSH Key Permissions: Make sure that the permissions of your SSH keys are well configured that is private keys in 600 and public keys in 644.
  • Authorized Keys: Ensure your public key is properly integrated in the ~/.ssh/authorized_keys file on both the Jump Host, and the target server.
  • User Accounts: Make sure that the user account exist on the Jump Host as well as on the target server; the account should have proper permissions.

3. SSH Version Compatibility:

  • Update OpenSSH: It is, therefore, important to ensure you are using a version of OpenSSH that supports the ProxyJump option – the current minimum version should be 7.3.
  • Server Compatibility: In this case make sure that the version of the SSH servers on the Jump Host and the target server correlate by being the same or compatible.

4. Configuration Errors:

SSH Config File Syntax: If you have not had much involvement with using SSH, then check your ~/.ssh/config file for any syntax errors or other issues. ProxyCommand Conflicts: The need to note is that if you are using both ProxyJump and ProxyCommand options, the latter is ignored. Delete configuration concerning the opponent’s moves that are currently in contrast to the current game situation.

Enhanced SSH Configurations

1. Combining ProxyJump with ProxyCommand:

Although ProxyJump makes Proxy configuration easier, ProxyCommand is more flexible to use to resolve non-SSH proxies which various behaviors may be needed.

Example Using ProxyCommand:

Host host_destination
    HostName server.destination.com
    User user
    ProxyCommand ssh -W %h:%p user@jump.example.com

2. Using ControlMaster for Connection Multiplexing:

Connection multiplexing in the SSH converts several SSH sessions into one particular network connection hence saving a lot of overheads and enhancing the performance.

Host *
    ControlMaster auto
    ControlPath ~/.ssh/sockets/%r@%h-%p
    ControlPersist 10m

3. Automating SSH Configurations:

For large scale server environments and each Linux server with unique and intricate access pattern, recommend using tools like Ansible or Puppet to automate the SSH or key management configuration.

4. Secure File Transfers Through Jump Hosts:

When copying files use tools like scp or rsync with switches like -J for transfer through the jump host securely.

scp -J user@jump.example.com file.txt user@server.destination.com:/path/to/destination/

Conclusion

SSH ProxyJump and Jump Hosts are one of the most valuable addons in managing a complex and secure network. Through these features, administrators are put in a position to be able to control easy access to remote servers in large network topologies as well as improve the security and efficiency of the running operations. Besides, such tools define the ways of enhancing the accessibility while strengthening the given organization’s network infrastructure against various cyber threats.