A command-line tool for managing authentication and SSH keys in GitLab. This tool simplifies authentication, cleans up old SSH keys, and automates the addition of new keys to GitLab.
- Authentication: Authenticate with a GitLab instance using device flow.
- SSH Key Management:
- Clean old SSH keys from GitLab by title prefix.
- Generate and upload new SSH keys to GitLab.
- Combined Workflow: A single command to authenticate, clean old keys, and add a new key.
- SSH Configuration Management:
- Generate and append SSH configuration for a specified host to the user's
~/.ssh/config
.
- Generate and append SSH configuration for a specified host to the user's
-
Clone the repository:
git clone https://github.com/atnomoverflow/git-auth-cli.git cd git-auth-cli
-
Build the project:
go build -o git-auth
-
Add the binary to your PATH (optional):
export PATH=$PATH:/path/to/git-auth
The tool requires a configuration file stored in the .git-auth
folder under the home directory. The file should be named config
.
[default]
url = "http://localhost:8000"
ssh-host = "localhost"
ssh-port = "2222"
ssh-prefix = "atnomoverflow"
ssh-path = "~/.git-auth-ssh"
client-id = "84c65c6208a18419df288dd5c29deeb1f270957d38f764414face2afa07b8947"
scope = ["api", "write_repository", "read_user"]
- Fields:
url
: The URL of your GitLab instance.ssh-host
: Host for SSH connections.ssh-port
: Port for SSH connections.ssh-prefix
: Prefix used for managing SSH keys.ssh-path
: Path to store SSH keys locally.client-id
: The GitLab application client ID.scope
: List of permissions required for the tool.
Ensure this file is present in ~/.git-auth/config
before using the tool.
Authenticate with the specified GitLab instance.
- Usage:
git-auth auth
- Description: Authenticates the user by fetching or refreshing the token and validates the login.
Remove SSH keys from GitLab by title prefix.
- Usage:
git-auth clean-keys [--prefix <prefix>]
- Options:
--prefix
: Specify a custom prefix for keys to clean. Defaults to the prefix defined in the configuration.
Generate and add a new SSH key to GitLab.
- Usage:
git-auth add-key
- Description: Generates a new SSH key pair and uploads the public key to the authenticated GitLab account. The private key is saved locally.
Authenticate, clean old keys, and add a new key to GitLab in a single command.
- Usage:
git-auth magic-auth
- Description: Combines the functionality of
auth
,clean-keys
, andadd-key
. Automatically handles login, removes old SSH keys, and uploads a new one.
Generates and appends SSH configuration for a specified host.
- Usage:
git-auth generate-ssh-config
- Description: This command generates an SSH configuration file for the provided host if one does not already exist. It adds the host, hostname, port, and identity file details into the user's SSH config file located at
~/.ssh/config
. If the configuration already exists, it will update the configuration for the host rather than appending.
-
Authenticate with GitLab:
git-auth auth
-
Remove SSH keys with a specific prefix:
git-auth clean-keys --prefix my-prefix
-
Add a new SSH key to GitLab:
git-auth add-key
-
Run the full workflow with
magic-auth
:git-auth magic-auth --prefix my-prefix
-
Generate and append SSH configuration for a host:
git-auth generate-ssh-config
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a clear description of your changes.
For questions or feedback, reach out to:
Montasser Abed Majid Zehri
📧 montasser.zehri@gmail.com