Gitea Auto Authenticate

Overview

Hosting Gitea in a docker container in a Linux box, I havent managed to enable SSH authentication through. I dont have time to experiment at the moment on another box so I need another solution.

CAUTION : Only use this solution on personal computer. Using Access Token generated in Gitea to authenticate will be easily accessible in clear.

Recipe

Use a Personal API Token to Authenticate.

Log Into Gitea. Go to the user / settings / applications area. Generate a new Token. I will generate one different token per laptop / pc I will use. I only select repository access with read and write privileges. Copy the token. Open a new Terminal, replace {new token} and {mylocalgitrepo.url} and execute the following :

1
2
3
4
5
6
MyToken={new-token}
MyRepo={mylocalgitrepo.url}

git config --global url."https://api:$MyToken@$MyRepo/".insteadOf "https://$MyRepo/"
git config --global url."https://ssh:$MyToken@$MyRepo/".insteadOf "ssh://git@$MyRepo/"
git config --global url."https://git:$MyToken@$MyRepo/".insteadOf "git@$MyRepo:"

When replacing {new token} with your token and {mylocalgitrepo.url} with your own repository, no quotes are needed. The information updated will be stored in your .gitconfig file :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
[user]
        email = [email protected]
        name = myname
[url "https://api:@{mylocalgitrepo.url}/"]
        insteadOf = https://{mylocalgitrepo.url}/
[url "https://ssh:@{mylocalgitrepo.url}/"]
        insteadOf = ssh://git@{mylocalgitrepo.url}/
[url "https://git:@{mylocalgitrepo.url}/"]
        insteadOf = git@{mylocalgitrepo.url}:
[url "https://api:[email protected]/"]
        insteadOf = https://mylocalgitrepo.url/
[url "https://ssh:[email protected]/"]
        insteadOf = ssh://[email protected]/
[url "https://git:[email protected]/"]
        insteadOf = [email protected]: