I am writing a new SFTP subsystem, which instead of reading files from a local file system, reads from an API interface. Here I was able to implement the SFTP subsystem. But I would like to get the FQDN the SFTP user is using to connect with my SFTP server.
To give more details about my scenario...
My SFTP server will have two or more CNAME (alias) records. For example, if the server name is sftp-testdomain.com
, then sample1.sftp-testdomain.com
, sample2.sftp-testdomain.com
CNAMEs will be available. I would like to get the FQDN in the SFTP subsystem to perform some checking before starting the SFTP server.
Can any one help me by pointing me to some reference or provide me some details about the feasibility of this requirement?
The SSH server (let alone SFTP subsystem), never learns a hostname the client used to find a server's IP address.
All communication happens using an IP address only.
The SSH/SFTP lacks a mechanism to provide the server with hostname to support virtual servers, that the HTTP or the FTP protocols have (the Host
header or the HOST
command respectively).
Even if there was such a mechanism, you might not be able to use the hostname provided for security checks. It's completely at will of the client, which of the server aliases it picks to provide to the server.
So the only solution is to distinguish the instances using an IP address or a port number. Or include the hostname into a username (something like user@host
or user_host
).
If you are writing a subsystem for OpenSSH SSH server, you can find an IP address and port used to connect to the SSH server from the SSH_CONNECTION
environment variable.
The username is in USER
and LOGNAME
variables.