SAS Communities Library

We’re smarter together. Learn from this collection of community knowledge and add your expertise.
BookmarkSubscribeRSS Feed

How to Clone a GitHub Repository in SAS Studio Using SSH

Started ‎04-27-2023 by
Modified ‎04-27-2023 by
Views 4,779

Read the post and watch the videos to learn how to successfully clone a GitHub repository in SAS Studio on SAS Viya using SSH authentication. The content of the post was developed with SAS Viya Long Term Support Release 2022.09, deployed to Azure. You will also learn a few tricks that will save you plenty of research time.

 

Initially, I tried many times to clone a GitHub repository in SAS Studio on SAS Viya using SSH and failed every time. What worked with SAS Viya 3.5 seemed not to work anymore, for some reason. When I finally succeeded, I learnt that there are a few elements that make all the difference between failure and success.

 

Learnings

  • The type of SSH keys you generate matters: ECDSA keys are accepted by SAS and GitHub.
  • The ownership of the folder where the SSH keys are stored is particularly important.
  • The clone and the SSH keys must be stored on a server file (network file share or mounted path). It will not work if you use SAS Content.

Pre-Requisites

 

Physical Infrastructure

 

In this example, SAS Viya is deployed to Azure. On Azure, the SAS Viya deployment comes with a virtual machine called jump-vm.

 

To generate the SSH keys, I am going to use this virtual machine (VM). The VM has access to folders on a Network File Share

(NFS). The NFS has been mounted in the SAS Compute pod at deployment time.

SAS Studio Settings

 

In SAS Environment Manager, your SAS Administrator must configure these properties for the Git Integration. Follow the link for more details.

bt_1_Clone a GitHub Repo using SSH - SAS Studio on SAS Viya Settings.mp4
Video Player is loading.
Current Time 0:00
Duration 0:00
Loaded: 0%
Stream Type LIVE
Remaining Time 0:00
 
1x
    • Chapters
    • descriptions off, selected
    • captions off, selected
      (view in My Videos)


      Steps to Clone using SSH

      Generate the SSH Keys

      The SAS Note 69005 - An SSH authentication fails and you see "...The specified URL or Public SSH key is invalid f... suggests that you are better off generating ECDSA keys when working with GitHub. ECDSA stands for Elliptic Curve Digital Signature Algorithm. RSA SHA-1 keys are no longer supported by GitHub, while ed25519 keys are not supported by SAS. On the Linux machine, for example the jump-vm, generate the ECDSA key:

       

       

      ssh-keygen -t ecdsa -b 521 -C 'your_email@domain.com'

       


      I chose an empty passphrase, although phrases are supported in SAS Studio.

      bt_2_Clone a GitHub Repo using SSH - Generate SSH Keys.mp4
      Video Player is loading.
      Current Time 0:00
      Duration 0:00
      Loaded: 0%
      Stream Type LIVE
      Remaining Time 0:00
       
      1x
        • Chapters
        • descriptions off, selected
        • captions off, selected
          (view in My Videos)

           

          Copy the Content of the SSH Public Key

          On the Linux machine where you generated the keys, copy the content of the public key:

           

           

          ls -la .ssh
          cat ~/.ssh/id_ecdsa.pub

           


          Add the SSH Public Key in GitHub


          To use SSH with a GitHub repository, you have to add your public key in your GitHub account. For more information, see Adding a new SSH key to your GitHub account.

          bt_3_Clone a GitHub Repo using SSH - Add SSH Public Key in GitHub.mp4
          Video Player is loading.
          Current Time 0:00
          Duration 0:00
          Loaded: 0%
          Stream Type LIVE
          Remaining Time 0:00
           
          1x
            • Chapters
            • descriptions off, selected
            • captions off, selected
              (view in My Videos)

               

              The Key text box hints you what type of keys GitHub accepts. I tried initially with a ssh-rsa key and it failed. I tried with an ed25519 key and it also failed, as these are not supported by SAS. Use ecdsa keys.

               

              bt_1_Add_Public_SSH_key_GitHub.png

              Select any image to see a larger version.
              Mobile users: To view the images, select the "Full" version at the bottom of the page.


              Get the GitHub Repository Details


              To create Git profile in SAS Studio, you would need:

              • The SSH URL, for example: git@github.com:bteleuca/git-demo.git
              • The GitHub user, for example bteleuca
              • The email registered with your GitHub account.


              Test Clone on the Jump VM


              To know if you can reach the GitHub repository and if you are allowed to clone, execute a quick test on your Jump VM:

               

               

              # clone the git demo repository in a new folder
              cd /viya-share/azuredm/code
              ls -la
              mkdir -p gitrepo1
              chmod -R 777 gitrepo1
              ls -la
              cd gitrepo1
              git clone git@github.com:bteleuca/git-demo.git
              cd git-demo
              ls -la

               

               

              You should see the cloned repository in a VM folder, proving the SSH clone works.

              bt_4_Clone a GitHub Repo using SSH - GutHub Details and Test Clone.mp4
              Video Player is loading.
              Current Time 0:00
              Duration 0:00
              Loaded: 0%
              Stream Type LIVE
              Remaining Time 0:00
               
              1x
                • Chapters
                • descriptions off, selected
                • captions off, selected
                  (view in My Videos)

                   

                  Download – Upload Your SSH Keys

                   

                  You can either: 

                   

                  1. Download the SSH keys from the VM and upload them in SAS Studio. This will automatically set the right file ownership.
                  2. Copy the SSH keys on the Jump VM. Do not forget to set the right ownership.

                   

                  Supposing you go with the first option:

                   

                  bt_5_Clone a GitHub Repo using SSH - Download Upload SSH Keys in SAS Studio.mp4
                  Video Player is loading.
                  Current Time 0:00
                  Duration 0:00
                  Loaded: 0%
                  Stream Type LIVE
                  Remaining Time 0:00
                   
                  1x
                    • Chapters
                    • descriptions off, selected
                    • captions off, selected
                      (view in My Videos)

                       

                      • Download the SSH keys from your VM.
                      • In SAS Studio:
                        • Create a folder e.g. sshkeys.
                        • Upload the public and the private SSH keys.

                       

                      Note that this folder has to be on a Network File Share (SAS Server files). It will not work if your keys are in a folder under SAS Content or My Folder.  

                       

                      Create a SSH Profile

                      From Manage Git connections > Add a Profile. Choose SSH:

                       

                      bt_6_Clone a GitHub Repo using SSH - Git Profile and Clone in SAS Studio.mp4
                      Video Player is loading.
                      Current Time 0:00
                      Duration 0:00
                      Loaded: 0%
                      Stream Type LIVE
                      Remaining Time 0:00
                       
                      1x
                        • Chapters
                        • descriptions off, selected
                        • captions off, selected
                          (view in My Videos)

                           

                          Fill in:

                           

                          • The SSH URL, for example: git@github.com:bteleuca/git-demo.git
                          • The GitHub user, for example bteleuca
                          • The email registered with your GitHub account.
                          • The passphrase is empty, in this example. Otherwise, fill in the passphrase if you chose one when you created the SSH keys.
                          • Select the public and the private key from the server folder.

                            bt_2_SAS-Studio-Git-SSH-Profile.png

                          Clone the Repository

                           

                          From Manage Git connections > Repositories > Clone a repository.

                          • Repository: Your GitHub SSH URL. E.g.: git@github.com:bteleuca/git-demo.git
                          • Server location: choose an empty folder or create a new one.
                          • Profile: Choose the profile you defined earlier.

                          bt_3_SAS-Studio-Git-SSH-Clone-Repsitory.png

                           

                          Success Looks Like This

                           

                          bt_4_SAS-Studio-Git-SSH-Successful-Clone.png

                           

                          Folder and SSH Keys Files Ownership

                           

                          On the Jump VM check the permissions and file ownership.

                           

                          bt_7_Clone a GitHub Repo using SSH - Adjust File Permissions.mp4
                          Video Player is loading.
                          Current Time 0:00
                          Duration 0:00
                          Loaded: 0%
                          Stream Type LIVE
                          Remaining Time 0:00
                           
                          1x
                            • Chapters
                            • descriptions off, selected
                            • captions off, selected
                              (view in My Videos)

                               

                              You will need sudo for this operation:

                               

                               

                              sudo ls -la /viya-share/azuredm/sshkeys

                               

                               

                              The ownership of the folder is really important! The number 1803... corresponds to the SAS Viya user identity that created the folder.

                               

                              Adjust the Permissions

                               

                              At this point the permissions are too wide for SSH keys. To be safe, restrict them to:

                              • Folder: chmod 700 -rwx------ Owner: read, write and execute.
                              • Public key: chmod 644 -rw-r--r-- Owner: read, write and execute. Group: read. Other: read.
                              • Private key: chmod 600 -rw------- Owner: read, write.

                               

                              sudo chmod 700 /viya-share/azuredm/sshkeys
                              sudo chmod 644 /viya-share/azuredm/sshkeys/id_ecdsa.pub
                              sudo chmod 600 /viya-share/azuredm/sshkeys/id_ecdsa
                              sudo ls -la /viya-share/azuredm/
                              sudo ls -la /viya-share/azuredm/sshkeys

                               

                              Push Some Files Remotely

                               

                              The objective is to test if you can push some files remotely. Although the clone operation works, you can be sure of your setup only when you manage to push.

                               

                              bt_8_Clone a GitHub Repo using SSH - Push Files Remotely.mp4
                              Video Player is loading.
                              Current Time 0:00
                              Duration 0:00
                              Loaded: 0%
                              Stream Type LIVE
                              Remaining Time 0:00
                               
                              1x
                                • Chapters
                                • descriptions off, selected
                                • captions off, selected
                                  (view in My Videos)

                                   

                                  Create a File

                                   

                                  Write a SAS program and save it in a folder under your cloned repository:

                                   

                                   

                                  PROC SORT DATA=sashelp.cars OUT=auto2 ;
                                    BY Model ;
                                  RUN ;
                                  PROC PRINT DATA=auto2 ;
                                  RUN ;

                                   

                                   

                                  Push Process

                                   

                                  • Optional: Create a new branch. Checkout to that branch.
                                  • Stage the changes.
                                  • Commit with a message.
                                  • Push the code.
                                  • Optional: Merge the branch back into main.
                                  • Look at the Git repository History tab in SAS Studio or, check remotely the changes (on the respective branch).

                                   

                                  Additional Git Operations in SAS Studio

                                   

                                  In this bonus section, you can watch how to add a repository in SAS Studio or delete a repository.

                                   

                                  bt_9_Clone a GitHub Repo using SSH - Add a Repository or Delete.mp4
                                  Video Player is loading.
                                  Current Time 0:00
                                  Duration 0:00
                                  Loaded: 0%
                                  Stream Type LIVE
                                  Remaining Time 0:00
                                   
                                  1x
                                    • Chapters
                                    • descriptions off, selected
                                    • captions off, selected
                                      (view in My Videos)

                                       

                                      Conclusions

                                       

                                      You can clone a GitHub repository in SAS Studio on SAS Viya. Attention points:

                                      • The type of SSH keys you generate matters: ECDSA keys are accepted by SAS and GitHub.
                                      • The ownership of the folder where the SSH keys are stored is particularly important.
                                      • The clone and the SSH keys must be stored on a server file (network file share or mounted path). It will not work if you use SAS Content.


                                      Additional Resources

                                       

                                      Thank you for your time reading this post. If you liked the post, give it a thumbs up! Please comment and tell us what you think about SAS Studio and Git SSH. If you wish to get more information, please write me an email.

                                       

                                      Find more articles from SAS Global Enablement and Learning here.

                                      Comments

                                      I really like the attention that the author pays to the security of the SSH key. This is good practice.

                                      I do have a question about the public key: why does SAS Studio need the public key in the first place? As long as the public key is registered in github (or other server that you want to authenticate with), the private key should be sufficient. Could you explain the rationale behind this approach?

                                      @NickSmisdom I am not sure why the public key has to be described in SAS Viya. Anyway, this posts deserves a "review", as a few things changed in regards to authentication. Will put it on my to-do.

                                      Version history
                                      Last update:
                                      ‎04-27-2023 11:04 PM
                                      Updated by:
                                      Contributors

                                      sas-innovate-white.png

                                      Our biggest data and AI event of the year.

                                      Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

                                      Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

                                       

                                      Register now!

                                      SAS AI and Machine Learning Courses

                                      The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

                                      Get started