How to clone a private git repository from Azure App Service Kudu console

Published Aug 15 2021 06:54 PM 5,067 Views
Microsoft

In azure app service Kudu console,  it is easy to clone a public git repository using "git clone" command,  when it comes to private repository,   you may find the same "git clone" command is stuck at "Cloning" step and isn't working any more.  This is simply because the repository is a private one and need to be authenticated,  in the meanwhile, we need an non-interactive way since Kudu console doesn't support popped-out windows.

gitclone1.png

 

There are in total 3 approaches to clone the private git repository:

 

Approach 1 (Username & Password):  

The most obvious way to fix this is to put your username and password in the git URL:

 

 

git clone https://$username:$password@github.com/$username/$repo -v

 

 

Example:

gitclone2.png

The side effect is that the user credentials would be saved in the .git/config file and everybody who can access Kudu console will be able to view the password.

 

Approach 2 (SSH key):

Step 1:   Send a GET request to the Kudu site to get the SSH key,   the URL looks like: https://xxxx.scm.azurewebsites.net/api/sshkey?ensurePublicKey=1

gitclone4.png

Step 2:   Remove the double quote and add the SSH key in the Github SSH key

gitclone5.png

 

Step 3:   Go to Kudu console and use the SSH way to clone the repository:

 

 

git clone git@github.com:$username/$repo.git

 

 

For example:

gitclone6.png

 

Approach 3 (Personal Access Token):

This approach is to use "personal access token" created in the github developer settings page:  https://github.com/settings/tokens

 

 

git clone https://$token@github.com/$username/$repo.git

 

 

Example:

gitclone3.png

%3CLINGO-SUB%20id%3D%22lingo-sub-2639991%22%20slang%3D%22en-US%22%3EHow%20to%20clone%20a%20private%20git%20repository%20from%20Azure%20App%20Service%20Kudu%20console%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2639991%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20azure%20app%20service%20Kudu%20console%2C%26nbsp%3B%20it%20is%20easy%20to%20clone%20a%20public%20git%20repository%20using%20%22git%20clone%22%20command%2C%26nbsp%3B%20when%20it%20comes%20to%20private%20repository%2C%26nbsp%3B%20%26nbsp%3Byou%20may%20find%20the%20same%20%22git%20clone%22%20command%20is%20stuck%20at%20%22Cloning%22%20step%20and%20isn't%20working%20any%20more.%26nbsp%3B%20This%20is%20simply%20because%20the%20repository%20is%20a%20private%20one%20and%20need%20to%20be%20authenticated%2C%26nbsp%3B%20in%20the%20meanwhile%2C%20we%20need%20an%20non-interactive%20way%20since%20Kudu%20console%20doesn't%20support%20popped-out%20windows.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitclone1.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302683i62B96FCB55385C72%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22gitclone1.png%22%20alt%3D%22gitclone1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20in%20total%20%3CSTRONG%3E3%20approaches%3C%2FSTRONG%3E%20to%20clone%20the%20private%20git%20repository%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSTRONG%3EApproach%201%20(Username%20%26amp%3B%20Password)%3A%26nbsp%3B%26nbsp%3B%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EThe%20most%20obvious%20way%20to%20fix%20this%20is%20to%20put%20your%20username%20and%20password%20in%20the%20git%20URL%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-git%22%3E%3CCODE%3Egit%20clone%20https%3A%2F%2F%24username%3A%24password%40github.com%2F%24username%2F%24repo%20-v%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExample%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitclone2.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302684i592AE589A9B6EB96%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22gitclone2.png%22%20alt%3D%22gitclone2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThe%20side%20effect%20is%20that%20the%20user%20credentials%20would%20be%20saved%20in%20the%20.git%2Fconfig%20file%20and%20everybody%20who%20can%20access%20Kudu%20console%20will%20be%20able%20to%20view%20the%20password.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSTRONG%3EApproach%202%20(SSH%20key)%3A%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EStep%201%3A%26nbsp%3B%20%26nbsp%3BSend%20a%20GET%20request%20to%20the%20Kudu%20site%20to%20get%20the%20SSH%20key%2C%26nbsp%3B%20%26nbsp%3Bthe%20URL%20looks%20like%3A%26nbsp%3B%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fxxxx.scm.azurewebsites.net%2Fapi%2Fsshkey%3FensurePublicKey%3D1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fxxxx.scm.azurewebsites.net%2Fapi%2Fsshkey%3FensurePublicKey%3D1%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitclone4.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302725i4EF5C7B19BEE1B12%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22gitclone4.png%22%20alt%3D%22gitclone4.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EStep%202%3A%26nbsp%3B%20%26nbsp%3BRemove%20the%20double%20quote%20and%20add%20the%20SSH%20key%20in%20the%20Github%20SSH%20key%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitclone5.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302726i4EA259BC6BD193CF%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22gitclone5.png%22%20alt%3D%22gitclone5.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStep%203%3A%26nbsp%3B%20%26nbsp%3BGo%20to%20Kudu%20console%20and%20use%20the%20SSH%20way%20to%20clone%20the%20repository%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-git%22%3E%3CCODE%3Egit%20clone%20git%40github.com%3A%24username%2F%24repo.git%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20example%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitclone6.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302727i6145563BA7129B9C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22gitclone6.png%22%20alt%3D%22gitclone6.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSTRONG%3EApproach%203%20(Personal%20Access%20Token)%3A%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EThis%20approach%20is%20to%20use%20%22personal%20access%20token%22%20created%20in%20the%20github%20developer%20settings%20page%3A%26nbsp%3B%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fsettings%2Ftokens%2C%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fsettings%2Ftokens%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-git%22%3E%3CCODE%3Egit%20clone%20https%3A%2F%2F%24token%40github.com%2F%24username%2F%24repo.git%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExample%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitclone3.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302693i3C5F5BAD65FA9117%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22gitclone3.png%22%20alt%3D%22gitclone3.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2639991%22%20slang%3D%22en-US%22%3E%3CP%3Enon-interactively%20cloning%20git%20repositories%20in%20azure%20app%20service%20kudu%20console%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2639991%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20App%20Service%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Aug 13 2021 03:08 AM
Updated by: