Skip to content

Commit fc353da

Browse files
SBrandeisjulien-c
andauthored
πŸ“ Document git clone over ssh (#736)
* πŸ“ Document git clone over ssh * πŸ“ New page about Git over SSH * Add in TOC * Update docs/hub/security-git-ssh.md Co-authored-by: Julien Chaumond <[email protected]> --------- Co-authored-by: Julien Chaumond <[email protected]>
1 parent eb7463b commit fc353da

8 files changed

+86
-6
lines changed

β€Ždocs/hub/_toctree.yml

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@
192192
sections:
193193
- local: security-tokens
194194
title: User Access Tokens
195+
- local: security-git-ssh
196+
title: Git over SSH
195197
- local: security-gpg
196198
title: Signing Commits with GPG
197199
- local: security-malware

β€Ždocs/hub/models-downloading.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Since all models on the Model Hub are Git repositories, you can clone the models
3636

3737
```bash
3838
git lfs install
39-
git clone <MODEL URL>
39+
git clone [email protected]:<MODEL ID> # example: git clone [email protected]:bigscience/bloom
4040
```
4141

4242
If you have write-access to the particular model repo, you'll also have the ability to commit and push revisions to the model.
43+
44+
Add your SSH public key to [your user settings](https://huggingface.co/settings/keys) to push changes and/or access private repos.

β€Ždocs/hub/repositories-getting-started.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,18 @@ Downloading repositories to your local machine is called *cloning*. You can use
8484

8585
```bash
8686
git clone https://huggingface.co/<your-username>/<your-model-name>
87-
cd <your-model-id>
87+
cd <your-model-name>
8888
```
8989

90+
You can clone over SSH with the following command:
91+
```bash
92+
git clone [email protected]:<your-username>/<your-model-name>
93+
cd <your-model-name>
94+
```
95+
96+
You'll need to add your SSH public key to [your user settings](https://huggingface.co/settings/keys) to push changes or access private repositories.
97+
98+
9099
### Set up
91100

92101
Now's the time, you can add any files you want to the repository! πŸ”₯

β€Ždocs/hub/repositories-next-steps.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ For example, say you have an upstream repository, **upstream**, and you just cre
4545
2. Clone your fork repository:
4646

4747
```
48-
git lfs clone https://huggingface.co/me/myfork.git
48+
git clone git@hf.co:me/myfork
4949
```
5050

5151
3. Fetch non-LFS files:
5252

5353
```
5454
cd myfork
5555
git lfs install --skip-smudge --local # affects only this clone
56-
git remote add upstream https://huggingface.co/friend/upstream.git
56+
git remote add upstream git@hf.co:friend/upstream
5757
git fetch upstream
5858
```
5959

β€Ždocs/hub/sample-factory.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The command line arguments are:
4040
Hugging Face repositories can be downloaded directly using `git clone`:
4141

4242
```
43-
git clone <URL of HuggingFace Repo>
43+
git clone [email protected]:<Name of HuggingFace Repo> # example: git clone [email protected]:bigscience/bloom
4444
```
4545

4646
## Using Downloaded Models with Sample-Factory

β€Ždocs/hub/security-git-ssh.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
```

β€Ždocs/hub/security.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Hugging Face is also [SOC2 Type 1 certified](https://us.aicpa.org/interestareas/
99
## Contents
1010

1111
- [User Access Tokens](./security-tokens)
12+
- [Git over SSH](./security-git-ssh)
1213
- [Signing commits with GPG](./security-gpg)
1314
- [Malware Scanning](./security-malware)
1415
- [Pickle Scanning](./security-pickle)

β€Ždocs/sagemaker/inference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Create your own `model.tar.gz` from a model from the πŸ€— Hub:
173173

174174
```bash
175175
git lfs install
176-
git clone https://huggingface.co/{repository}
176+
git clone git@hf.co:{repository}
177177
```
178178

179179
2. Create a `tar` file:

0 commit comments

Comments
Β (0)