Skip to content

Commit 44bc863

Browse files
committed
Fix ProxyJump to use correct username from SSH config
ET was using the destination username for ProxyJump connections instead of the jumphost's username defined in SSH config. With this SSH config: Host telie User corona Host step User anl ProxyJump telie Running 'et step' would incorrectly try 'anl@home.alelec.net' instead of 'corona@home.alelec.net' for the jumphost connection. Fix: Parse jumphost SSH config to extract its username, use that for the -J flag. Fallback to local username if not specified.
1 parent 7b3e9b1 commit 44bc863

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/terminal/TerminalClientMain.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,15 @@ int main(int argc, char** argv) {
298298
// Extract hostname from [user@]host[:sshport] format for ET socket
299299
// connection
300300
string jumphostName = jumphost;
301+
string jumphostUser = "";
302+
string jumphostHostPort = jumphost; // Preserve host[:port] portion
301303

302304
// Strip user@ prefix if present
303305
size_t atIndex = jumphostName.find("@");
304306
if (atIndex != string::npos) {
307+
jumphostUser = jumphostName.substr(0, atIndex);
305308
jumphostName = jumphostName.substr(atIndex + 1);
306-
} else {
307-
// If no user@ prefix, add it to jumphost for SSH
308-
jumphost = username + "@" + jumphost;
309+
jumphostHostPort = jumphostName; // host[:port] without user@
309310
}
310311

311312
// Strip :port suffix if present (SSH port, not ET port)
@@ -314,7 +315,7 @@ int main(int argc, char** argv) {
314315
jumphostName = jumphostName.substr(0, colonIndex);
315316
}
316317

317-
// Resolve jumphost alias to actual hostname via SSH config
318+
// Resolve jumphost alias to actual hostname and username via SSH config
318319
// jumphostName might be a Host alias (e.g., "telie") that needs
319320
// resolution
320321
{
@@ -334,6 +335,12 @@ int main(int argc, char** argv) {
334335
jumphostName = string(jumphostOptions.host);
335336
SAFE_FREE(jumphostOptions.host);
336337
}
338+
// Extract username from SSH config if not already specified
339+
if (jumphostUser.empty() && jumphostOptions.username) {
340+
jumphostUser = string(jumphostOptions.username);
341+
LOG(INFO) << "Using jumphost username from SSH config: "
342+
<< jumphostUser;
343+
}
337344
// Clean up other allocated fields in jumphostOptions
338345
SAFE_FREE(jumphostOptions.username);
339346
SAFE_FREE(jumphostOptions.sshdir);
@@ -346,6 +353,17 @@ int main(int argc, char** argv) {
346353
free(jumphost_home_dir);
347354
}
348355

356+
// If still no username, use local username as fallback
357+
if (jumphostUser.empty()) {
358+
char* localUsernamePtr = ssh_get_local_username();
359+
jumphostUser = string(localUsernamePtr);
360+
SAFE_FREE(localUsernamePtr);
361+
}
362+
363+
// Reconstruct jumphost with correct username for SSH -J flag
364+
// Preserve the original host[:port] format
365+
jumphost = jumphostUser + "@" + jumphostHostPort;
366+
349367
socketEndpoint.set_name(jumphostName);
350368
socketEndpoint.set_port(result["jport"].as<int>());
351369
} else {

0 commit comments

Comments
 (0)