Skip to content

Add support for custom SSH and SCP commands via environment variables #10730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

cmbrose
Copy link
Member

@cmbrose cmbrose commented Apr 4, 2025

Fixes: #9244

Description

This PR adds support for customizing the SSH and SCP commands used by the GitHub CLI's codespace functionality through environment variables. Users can now specify alternative SSH/SCP commands with additional options, providing greater flexibility and control over their codespace connections.

Features Added

  • Added support for two new environment variables:

    • GH_CS_SSH_COMMAND: Allows customization of the SSH command used for gh cs ssh
    • GH_CS_SCP_COMMAND: Allows customization of the SCP command used for gh cs cp
  • Implemented robust command-line parsing using the github.com/google/shlex library to handle quoted arguments and complex command structures

  • Modified the newSSHCommand and newSCPCommand functions to incorporate arguments from the environment variables

Implementation Details

  • The implementation uses the shlex library to parse command lines with quoted arguments, ensuring proper handling of complex command structures
  • Custom arguments from environment variables are inserted at the beginning of the command arguments list
  • Comprehensive unit tests were added to verify the functionality with various command formats

Example Usage

# Use SSH with verbose output
GH_CS_SSH_COMMAND="ssh -v" gh cs ssh -c my-codespace

# Use SSH with custom options
GH_CS_SSH_COMMAND="ssh -o LogLevel=DEBUG" gh cs ssh -c my-codespace

# Use a custom SSH binary with options
GH_CS_SSH_COMMAND="/path/to/custom/ssh -v -o IdentityFile=/custom/key" gh cs ssh -c my-codespace

# Similar usage for SCP commands
GH_CS_SCP_COMMAND="scp -v" gh cs cp -e README.md remote:/tmp/

Testing

  1. Unit tests that verify the parsing of environment variables with various command formats
  2. Manual testing with real codespaces, confirming that both SSH and SCP commands work as expected

@cmbrose cmbrose requested a review from a team as a code owner April 4, 2025 18:14
@cmbrose cmbrose temporarily deployed to cli-automation April 4, 2025 18:14 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide environment variable to specify alternative SSH command for gh cs ssh
1 participant