|
| 1 | +# Git over SSH |
| 2 | + |
| 3 | +You can access and write data in repositories on huggingface.co using SSH (Secure Shell Protocol). When you connect via SSH, you authenticate using a private key file on your local machine. |
| 4 | + |
| 5 | +Some actions, such as pushing changes, or cloning private repositories, will require you to upload your SSH public key to your account on huggingface.co. |
| 6 | + |
| 7 | +You can use a pre-existing SSH key, or generate a new one specifically for huggingface.co. |
| 8 | + |
| 9 | +## Checking for existing SSH keys |
| 10 | + |
| 11 | +If you have an existing SSH key, you can use that key to authenticate Git operations over SSH. |
| 12 | + |
| 13 | +SSH keys are usually located under `~/.ssh` on Mac & Linux, and under `C:\\Users\\<username>\\.ssh` on Windows. List files under that directory and look for files of the form: |
| 14 | + |
| 15 | +- id_rsa.pub |
| 16 | +- id_ecdsa.pub |
| 17 | +- id_ed25519.pub |
| 18 | + |
| 19 | +Those files contain your SSH public key. |
| 20 | + |
| 21 | +If you don't have such file under `~/.ssh`, you will have to [generate a new key](#generating-a-new-ssh-keypair). Otherwise, you can [add your existing SSH public key(s) to your huggingface.co account](#add-a-ssh-key-to-your-account). |
| 22 | + |
| 23 | +## Generating a new SSH keypair |
| 24 | + |
| 25 | +If you don't have any SSH keys on your machine, you can use `ssh-keygen` to generate a new SSH key pair (public + private keys): |
| 26 | + |
| 27 | +``` |
| 28 | +$ ssh-keygen -t ed25519 -C "[email protected]" |
| 29 | +``` |
| 30 | + |
| 31 | +We recommend entering a passphrase when you are prompted to. A passphrase is an extra layer of security: it is a password that will be prompted whenever you use your SSH key. |
| 32 | + |
| 33 | +Once your new key is generated, add it to your SSH agent with `ssh-add`: |
| 34 | + |
| 35 | +``` |
| 36 | +$ ssh-add ~/.ssh/id_ed25519 |
| 37 | +``` |
| 38 | + |
| 39 | +If you chose a different location than the default to store your SSH key, you would have to replace `~/.ssh/id_ed25519` with the file location you used. |
| 40 | + |
| 41 | +## Add a SSH key to your account |
| 42 | + |
| 43 | +To access private repositories with SSH, or to push changes via SSH, you will need to add your SSH public key to your huggingface.co account. You can manage your SSH keys [in your user settings](https://huggingface.co/settings/keys). |
| 44 | + |
| 45 | +To add a SSH key to your account, click on the "Add SSH key" button. |
| 46 | + |
| 47 | +Then, enter a name for this key (for example, "Personal computer"), and copy and paste the content of your **public** SSH key in the area below. The public key is located in the `~/.ssh/id_XXXX.pub` file you found or generated in the previous steps. |
| 48 | + |
| 49 | +Click on "Add key", and voilΓ ! You have added a SSH key to your huggingface.co account. |
| 50 | + |
| 51 | + |
| 52 | +## Testing your SSH authentication |
| 53 | + |
| 54 | +Once you have added your SSH key to your huggingface.co account, you can test that the connection works as expected. |
| 55 | + |
| 56 | +In a terminal, run: |
| 57 | +``` |
| 58 | + |
| 59 | +``` |
| 60 | + |
| 61 | +If you see a message with your username, congrats! Everything went well, you are ready to use git over SSH. |
| 62 | + |
| 63 | +Otherwise, if the message states something like the following, make sure your SSH key is actually used by your SSH agent. |
| 64 | +``` |
| 65 | +Hi anonymous, welcome to Hugging Face. |
| 66 | +``` |
0 commit comments