How to Clone a GitHub Repository in SAS Studio Using SSH
- Article History
- RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
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.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
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.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
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.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
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.
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.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
Download – Upload Your SSH Keys
You can either:
- Download the SSH keys from the VM and upload them in SAS Studio. This will automatically set the right file ownership.
- Copy the SSH keys on the Jump VM. Do not forget to set the right ownership.
Supposing you go with the first option:
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
- 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:
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
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.
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.
Success Looks Like This
Folder and SSH Keys Files Ownership
On the Jump VM check the permissions and file ownership.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
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.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
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.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
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
- Understanding Git Integration in SAS Studio - SAS Documentation.
- For SAS Viya 3.5 / Studio 5.2 see the YouTube by @XavierBizoux : Setting up Git repository in SAS Studio 5.
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.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@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.