Skip to content

pingz/feldspar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Preface

This project is mainly generated by large language models. It really speeds up the writing process. Of course, there is still some manual intervention to solve certain issues. This instruction document is also generated by large language models. To be honest, it’s better than what I could write myself.

Program Function Overview

The main function of this Go program is to implement a local proxy that can forward the traffic of a local port to a remote server through an SSH tunnel. The program will read the relevant configuration information from the configuration file forward_config.toml and load the necessary configuration for the SSH connection from the user’s SSH configuration file ~/.ssh/config. Finally, it will start the proxy service.

Environment Preparation

Go Language Environment

Make sure that the Go language is installed on your system and the Go version meets the requirements of the program.

Installation of Dependent Libraries

This program depends on some third - party libraries. You need to use the following commands to install them:

go get github.com/kevinburke/ssh_config
go get golang.org/x/crypto/ssh
go get github.com/BurntSushi/toml

Configuration File Instructions

SSH Configuration File

The program will read relevant configuration information, such as the username, hostname, port number, and the path of the private key file, from the user’s SSH configuration file ~/.ssh/config. Make sure that this file exists and is configured correctly.

Forwarding Configuration File

The program will read the forward_config.toml file to obtain the relevant configuration information for forwarding. The content format of this file is as follows:

remote_host = "example.com" # Hostname of the remote server
remote_port = "8080" # Port number of the remote server
local_port = "8081" # Local listening port number
ssh_host = "ssh.example.com" # Hostname of the SSH server
timeout = 30 # Connection timeout (in seconds)

Private Key File Instructions

Configuration of the Private Key File Path

Make sure that the correct IdentityFile, i.e., the path of the SSH private key file, is configured for ssh_host in ~/.ssh/config.

Setting the Private Key Password

If the private key file is password - protected, you need to set the environment variable SSH_PASSCODE to the password of the private key. For example:

export SSH_PASSCODE="your_passphrase"

Compiling and Running the Program

Compiling the Program

In the terminal, navigate to the directory where the program is located and use the following command to compile the program:

go build -o ssh_forward main.go

This will generate an executable file named ssh_forward.

Running the Program

After compilation, use the following command to run the program:

./ssh_forward

If all configurations are correct, the program will start and output relevant information about the proxy service, for example: Forwarding proxy started on localhost:8081 -> example.com:8080 via ssh.example.com

Notes

Security

The program uses ssh.InsecureIgnoreHostKey() to ignore SSH host key verification. This can be used in a test environment, but it is not recommended in a production environment because of security risks.

Error Handling

If an error occurs during the program’s execution, the corresponding error information will be output in the terminal. You can troubleshoot and fix the issue based on the error information.

Through the above steps, you can use this program to forward the traffic from a local port to a remote server.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages