4.7 Accessing code
Here we can talk about how to use the servers with GitHub code management. Essentially, you can work with projects and GitHub repositories on RStudio Server exactly like you can on your personal machine. One major difference is how to set up GitHub authentication, which is a little different on the servers than it would be on your personal machine. So we can provide explicit instructions on doing that.
Please refer to this
section
of the emLab SOP for directions on how to set up and manage git and
GitHub for your new server workspace. One important difference between
your personal laptop and using a server is that file permissions may be
such that other users can see and sometimes read or write files in your
directories. Ideally, any confidential information such as your git
credentials should be secured differently from your personal computer.
Step 6 of the Git and Github section of the emLab manual is therefore
not recommended in a multi-user server environment because your token
may end up viewable to other users as plain text.
Instead of storing your Personal Authentication Token (PAT) as plain text, it is recommended to use one of the following options. Using either of these two approaches will also mean that credentials are stored between sessions, which should make the user experience a bit easier. The first approach, using an SSH key, is recommended
Use an SSH key instead of a PAT
Set up your SSH key on the GRIT server.
If you are not using R Studio Server, or prefer to use the terminal, follow these instructions:
You can generate a new SSH key with the terminal command
- ssh-keygen -t ed25519 -C “email@example.com”
You are prompted to select a location (hit enter for the default location)
You are prompted to set a password (hit enter to not require one)
Start your SSH agent in the background with
- eval “$(ssh-agent -s)”
Add your private key to the SSH agent with
- ssh-add ~/.ssh/id_ed25519
Copy your public key with
- cat ~/.ssh/id_rsa.pub | xclip -selection clipboard
If you are using R Studio Server and you prefer to not use the terminal approach, the instructions are a bit more streamlined. Follow the instructions in this link.
- If after going through these instructions you prefer to not use a password, you can remove it using the instructions provided in this link.
Add your public key to your GitHub account
GitHub > Settings > SSH and GPG keys > New SSH key
Paste in your key (either from Step 6 in the terminal option above, or copied from R Studio Server in the R Studio option above)
Now you can clone your repository onto the GRIT server. This means that you need to either: 1) when cloning the repository for the first time you need to use the SSH url rather than the HTTPS url; or 2) if you’ve already clone the repository, set your repository URL to the SSH version
If cloning a repo for the first time using R Studio Server, you can simply click “File > New Project > Version Control > Git”, and then enter your repo’s SSH link
- git@github.com:username/example_repo.git (for example, this might look like git@github.com:emlab-ucsb/ocean-ghg.git)
Alternatively, in the terminal You can manually set specific repo URLs to SSH with:
- git remote set-url origin git@github.com:username/example_repo.git (for example, this might look like git@github.com:emlab-ucsb/ocean-ghg.git)
Caching your PAT temporarily
Create a PAT on GitHub
Add credential cache timeout instructions to your git config file
git config –global credential.helper ‘cache –timeout=3600’
Adjust the timeout length (in seconds) as needed
Push changes to GitHub
When prompted enter your username
For the password enter your PAT
- Future pushes will not not require you to enter credentials within the timeout window
This is not a good long term solution because you will need to re-enter your credentials anytime the server restarts or when your cache timeout ends