###### tags: `github` `git`
# Git Submodule permission issue (Github SSH account)
The error msg shows whne trying to update the submodule of my github repo (```git submodule update --init --recursive```)
## Issue
```
(base) macbookpro4eric@Erics-MacBook-Pro dappio-ui-v2 % git submodule update --init --recursive
Submodule 'nft-staking' (git@github.com:DappioWonderland/nft-staking.git) registered for path 'nft-staking'
Cloning into '/Users/macbookpro4eric/Projects/dappio/dappio-ui-v2/nft-staking'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@github.com:DappioWonderland/nft-staking.git' into submodule path '/Users/macbookpro4eric/Projects/dappio/dappio-ui-v2/nft-staking' failed
Failed to clone 'nft-staking'. Retry scheduled
Cloning into '/Users/macbookpro4eric/Projects/dappio/dappio-ui-v2/nft-staking'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
```
[This tells the remote has an SSH URL. So the authentication error means that either I don’t have an SSH key available on the machine (possibly not loaded into SSH agent), or the key I have hasn’t been added to your GitHub account.](https://github.community/t/fatal-could-not-read-from-remote-repository-please-make-sure-you-have-the-correct-access-rights-and-the-repository-exists/192364)
## github remote integration with local ssh key
### [Checking for existing SSH keys](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys)
Enter ls -al ~/.ssh to see if existing SSH keys are present.
```
$ ls -al ~/.ssh
```
Lists the files in your .ssh directory, if they exist
Check the directory listing to see if you already have a public SSH key. By default, the filenames of supported public keys for GitHub are one of the following.
- [x] id_rsa.pub (This is my case)
- [ ] id_ecdsa.pub
- [ ] id_ed25519.pub
### [Adding your SSH key to the ssh-agent](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)
If you're using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.
First, check to see if your ~/.ssh/config file exists in the default location.
```
$ open ~/.ssh/config
> The file /Users/you/.ssh/config does not exist.
```
If the file doesn't exist, create the file.
```
$ touch ~/.ssh/config
```
Open your ~/.ssh/config file, then modify the file to contain the following lines. If your SSH key file has a different name or path than the example code, modify the filename or path to match your current setup.
```
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
```
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
```
ssh-add -K ~/.ssh/id_rsa
```
### [Adding a new SSH key to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)
Follow the doc step by step.

Then we can try to run the submodlue update command and it should now be working fine.
```
(base) macbookpro4eric@Erics-MacBook-Pro dappio-ui-v2 % git submodule update --init --recursive
Cloning into '/Users/macbookpro4eric/Projects/dappio/dappio-ui-v2/nft-staking'...
Submodule path 'nft-staking': checked out '7761xx2d24xxa029a7ee7'
```