Home  >  Article  >  Backend Development  >  How to get connection string for authentication callback in SSH in golang?

How to get connection string for authentication callback in SSH in golang?

PHPz
PHPzforward
2024-02-09 15:40:081006browse

如何在 golang 中的 SSH 中获取身份验证回调的连接字符串?

php editor Youzi will introduce to you how to get the connection string of the authentication callback in SSH in golang. In the SSH protocol, the authentication callback is an important link, which is used to verify the client's identity and establish a secure connection. In order to obtain the connection string for the authentication callback, we can use the functions and methods provided by the ssh package in golang with the correct parameters and settings. In the following article, we will explain this process in detail to help you handle SSH connections and authentication flexibly in golang.

Question content

My server configuration code is:

serverConfig := ssh.ServerConfig{
        PublicKeyCallback: func(c ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) {
        ...
    }
}

I start the ssh connection using something like ssh://user@host:port/path. How do I get the path part of the ssh connection string in this callback or any other callback that can check the user key/password?

Solution

SSH is different from http, which contains ssh://user@host:port/path. The format is indeed user@host:port but it does not require ssh:// and path construction. In your question, PublicKeyCallback is using the public key. If you are performing a custom action, do it outside of PublicKeyCallback.

The above is the detailed content of How to get connection string for authentication callback in SSH in golang?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete