Back to Codeberg

Feature request: add ability to add ssh keys from command line #234

forgejo-contrib-forgejo-cli-issues-234.md

latest13.4 KB
Original Source

forgejo-contrib/forgejo-cli

Watch20

Star402

Fork

You've already forked forgejo-cli

51

CodeIssues 44Pull requests 8Releases 11Packages 2WikiActivity

Feature request: add ability to add ssh keys from command line #234

New issue

Closed

opened 2025-11-01 03:14:39 +01:00 by razzi · 5 comments

razzi commented 2025-11-01 03:14:39 +01:00

Copy link

I'd like to be able to add an ssh key to my codeberg account from the command line.

Where exactly this should go is a bit tricky, since the CLI already has:

fj auth add-key

However this is for application tokens, not ssh keys:

text
$ fj auth add-key --help
Add an application token for an instance

Use this if `fj auth login` doesn't work

Usage: fj auth add-key <USER> [KEY]

A couple places this functionality could live:

  • fj ssh-key add
  • fj auth add-ssh-key

I'd like to be able to add an ssh key to my codeberg account from the command line. Where exactly this should go is a bit tricky, since the CLI already has: fj auth add-key However this is for application tokens, not ssh keys: $ fj auth add-key --help Add an application token for an instance Use this if `fj auth login` doesn't work Usage: fj auth add-key \<USER\> [KEY] A couple places this functionality could live: - fj ssh-key add - fj auth add-ssh-key

Cyborus added the Kind/Feature label 2025-11-01 03:32:12 +01:00

Cyborus commented 2025-11-01 03:51:22 +01:00

Member

Copy link

My thought for the name would be upload-key, which would allow it to work for SSH or GPG keys. I'd put it in either fj upload-key or fj user upload-key.

It should warn against accidentally trying to upload a private key, ideally by rejecting any file that doesn't have the .pub extension to avoid loading the contents, but definitely not sending it over a network to let it be rejected by Forgejo.

My thought for the name would be upload-key, which would allow it to work for SSH or GPG keys. I'd put it in either fj upload-key or fj user upload-key. It should warn against accidentally trying to upload a private key, ideally by rejecting any file that doesn't have the .pub extension to avoid loading the contents, but *definitely* not sending it over a network to let it be rejected by Forgejo.

Cyborus commented 2025-11-02 15:20:32 +01:00

Member

Copy link

upload-key may be too specific; there's endpoints to list and delete current keys, that'd be good to include too. fj user key upload, fj user key list, and fj user key delete look good to me. While that is kinda long, I'm hesitant to put it in fj key, as that could be confusing with fj auth, which is specifically for authenticating fj to a forgejo instance.

upload-key may be too specific; there's endpoints to list and delete current keys, that'd be good to include too. fj user key upload, fj user key list, and fj user key delete look good to me. While that is kinda long, I'm hesitant to put it in fj key, as that could be confusing with fj auth, which is specifically for authenticating fj to a forgejo instance.

razzi commented 2025-11-13 04:32:03 +01:00

Author

Copy link

I like fj user key upload :)

I like fj user key upload :)

👍 1

LordMZTE commented 2025-11-22 22:42:59 +01:00

Collaborator

Copy link

GPG keys and SSH keys are actually treated as separate things by the API, the former being addressed by /user/gpg_keys and the latter by /user/keys. It might make sense to introduce two separate subcommands here, accordingly.

Maybe fj user key and fj user gpg or fj user gpg-key?

They'd probably also work differently. For uploading an SSH key, all we should need to do is read in a file, maybe guess a default name for the key from the file content like the web UI does and send that over. The GPG keyring, however, is an opaque data structure (at least per my limited understanding) and we probably should invoke the GPG CLI to get the user's key for upload. We could alternatively also use some library for reading the GPG key but I'd probably prefer the former option to keep dependency count low (and someone who wants to upload a GPG key will have gpg installed).

GPG keys and SSH keys are actually treated as separate things by the API, the former being addressed by /user/gpg_keys and the latter by /user/keys. It might make sense to introduce two separate subcommands here, accordingly. Maybe fj user key and fj user gpg or fj user gpg-key? They'd probably also work differently. For uploading an SSH key, all we should need to do is read in a file, maybe guess a default name for the key from the file content like the web UI does and send that over. The GPG keyring, however, is an opaque data structure (at least per my limited understanding) and we probably should invoke the GPG CLI to get the user's key for upload. We could alternatively also use some library for reading the GPG key but I'd probably prefer the former option to keep dependency count low (and someone who wants to upload a GPG key will have gpg installed).

👍 1

Cyborus commented 2025-11-23 01:37:54 +01:00

Member

Copy link

That sounds good. I haven't worked a whole lot with GPG keys (aside from a couple encrypted emails, but Thunderbird handled a lot of it for me), so I sort of implicitly assumed they worked similarly enough we could handle the two cases transparently. Since not, I agree two commands makes more sense.

Maybe fj user key and fj user gpg or fj user gpg-key?

I like the first two 👍

That sounds good. I haven't worked a whole lot with GPG keys (aside from a couple encrypted emails, but Thunderbird handled a lot of it for me), so I sort of implicitly assumed they worked similarly enough we could handle the two cases transparently. Since not, I agree two commands makes more sense. > Maybe fj user key and fj user gpg or fj user gpg-key? I like the first two 👍

LordMZTE self-assigned this 2025-11-23 09:30:49 +01:00

LordMZTE referenced this issue from a pull request that will close it, 2025-11-23 14:50:18 +01:00 feat: SSH and GPG key commands #241

Cyborus closed this issue 2025-11-27 02:31:04 +01:00

Cyborus added this to the v0.4.0 milestone 2025-12-01 17:02:00 +01:00

Sign in to join this conversation.

No Branch/Tag specified

BranchesTags

main

renovate/lock-file-maintenance

renovate/serde-saphyr-0.x

docs/contributing

no-port-in-refspec

login/v16.next.forgejo.org

crates-io-publish

0.5.x

compile-time-fluent

0.4.x

localization-alias-demo

api_url_field

v0.5.0

v0.4.1

v0.4.0

v0.3.0

v0.2.0

v0.1.1

v0.1.0

v0.0.4

v0.0.3

v0.0.2

v0.0.1

Labels

Clear labels[ Kind/Breaking Breaking change that won't be backward compatible

](#)[ Kind/Bug Something is not working

](#)[ Kind/Design Discussion about UI/UX design

](#)[ Kind/Documentation Documentation changes

](#)[ Kind/Enhancement Improve existing functionality

](#)[ Kind/Feature New functionality

](#)[ Kind/Security This is security issue

](#)[ Kind/Testing Issue or pull request related to testing

](#)[ Kind/Upstream This is an issue with upstream software (Forgejo) that is probably not our fault

](#)

[ Priority

Critical The priority is critical

](#)[ Priority

High The priority is high

](#)[ Priority

Low The priority is low

](#)[ Priority

Medium The priority is medium

](#)

[ Reviewed

Confirmed Issue has been confirmed

](#)[ Reviewed

Duplicate This issue or pull request already exists

](#)[ Reviewed

Invalid Invalid issue

](#)[ Reviewed

Won't Fix This issue won't be fixed

](#)

[ Status

Abandoned Somebody has started to work on this but abandoned work

](#)[ Status

Blocked Something is blocking this issue or pull request

](#)[ Status

Need More Info Feedback is required to reproduce issue or to continue work

](#)

[ Suspicious

](#)

No labels Kind/Breaking Kind/Bug Kind/Design Kind/Documentation Kind/Enhancement Kind/Feature Kind/Security Kind/Testing Kind/Upstream [ Priority

Critical ](/forgejo-contrib/forgejo-cli/issues?labels=173012) [ Priority

High ](/forgejo-contrib/forgejo-cli/issues?labels=173013) [ Priority

Low ](/forgejo-contrib/forgejo-cli/issues?labels=173015) [ Priority

Medium ](/forgejo-contrib/forgejo-cli/issues?labels=173014) [ Reviewed

Confirmed ](/forgejo-contrib/forgejo-cli/issues?labels=173007) [ Reviewed

Duplicate ](/forgejo-contrib/forgejo-cli/issues?labels=173005) [ Reviewed

Invalid ](/forgejo-contrib/forgejo-cli/issues?labels=173006) [ Reviewed

Won't Fix ](/forgejo-contrib/forgejo-cli/issues?labels=173008) [ Status

Abandoned ](/forgejo-contrib/forgejo-cli/issues?labels=173011) [ Status

Blocked ](/forgejo-contrib/forgejo-cli/issues?labels=173010) [ Status

Need More Info ](/forgejo-contrib/forgejo-cli/issues?labels=173009) Suspicious

Milestone

Clear milestone

No items

No milestone v0.4.0

Projects

Clear projects

No items

No project

Assignees

Clear assignees

No assignees

LordMZTE

3 participants

Notifications Subscribe

Due date

The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference

forgejo-contrib/forgejo-cli#234

WritePreview

Loading…

Add table

| Rows | | | Columns | |

CancelOK

Add a link

Url Description Hint: With a URL in your clipboard, you can paste directly into the editor to create a link.

CancelOK

CancelSave

Reference in a new issue

Repository

forgejo-contrib/forgejo-cli

Title

Body

Create issue

No description provided.

Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?

No Yes