BookmarkSubscribeRSS Feed

How to Clone a GitHub Repository in SAS Studio Using SSH

Started ‎04-27-2023 by
Modified ‎04-27-2023 by
Views 3,300

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.


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.

 

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.

 

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.

 

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:

 

 

  • 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:

 

 

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.

 

 

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.

 

 

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.

 

 

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.

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started