> For the complete documentation index, see [llms.txt](https://docs.ititanhosting.ro/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ititanhosting.ro/docs/english/vps/linux/how-to-install-git-and-set-up-ssh-keys.md).

# How to install Git and set up SSH keys

Git is the standard for version control. If you plan to write code, deploy projects, or contribute to open source, you need it on your VPS. SSH keys let you authenticate to GitHub, GitLab, or Bitbucket without typing a password every time.

### Step 1: Install Git

Ubuntu makes this easy:

```bash
sudo apt update
sudo apt install git -y
```

Check the version:

```bash
git --version
```

### Step 2: Configure your identity

Git needs to know who you are for the commits you make:

```bash
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
```

Use the same name and email you have on GitHub.

### Step 3: Generate an SSH key

An SSH key comes in two parts. A private key that stays on your server, and a public key that you give to GitHub. Generate one with:

```bash
ssh-keygen -t ed25519 -C "your@email.com"
```

You will be asked where to save it. Press Enter to accept the default location (`~/.ssh/id_ed25519`). You can also set a passphrase for extra security, or leave it empty.

### Step 4: Add the key to your SSH agent

```bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
```

### Step 5: Copy your public key

Display the public key so you can copy it:

```bash
cat ~/.ssh/id_ed25519.pub
```

It will look something like this:

```
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOc... your@email.com
```

Select and copy the entire line.

### Step 6: Add the key to GitHub

1. Go to [github.com/settings/keys](https://github.com/settings/keys)
2. Click **New SSH key**
3. Give it a name like `ITITAN VPS`
4. Paste your public key in the **Key** field
5. Click **Add SSH key**

### Step 7: Test the connection

```bash
ssh -T git@github.com
```

You should see:

```
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
```

### Cloning a repository

Now you can clone any repository you have access to:

```bash
git clone git@github.com:username/repository.git
```

Notice the `git@github.com:` prefix instead of `https://`. That is the SSH format.

### Useful Git commands for quick reference

| Command                       | What it does                      |
| ----------------------------- | --------------------------------- |
| `git status`                  | Check what files changed          |
| `git add filename`            | Stage a file for commit           |
| `git commit -m "message"`     | Commit staged changes             |
| `git push`                    | Send commits to remote            |
| `git pull`                    | Get latest changes from remote    |
| `git log --oneline`           | View commit history               |
| `git branch`                  | List branches                     |
| `git checkout -b branch-name` | Create and switch to a new branch |

### Managing multiple SSH keys

If you have multiple GitHub accounts or other services, create a config file:

```bash
nano ~/.ssh/config
```

Add entries like this:

```
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519

Host gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_ed25519_gitlab
```

### Common issues

**"Permission denied (publickey)"** means the public key was not added to GitHub, or you are using the wrong key. Check that you copied the right file (`id_ed25519.pub`, not `id_ed25519`).

**"Please make sure you have the correct access rights"** usually means your key is not associated with the repository. Make sure you are added as a collaborator or have access to the repo.

### Conclusion

Git and SSH keys take ten minutes to set up and make your life much easier. Every time you skip typing a password, you will be glad you did it.
