You will be using SSH for your research!
~/.ssh
folderssh username@remote_server.org
ssh username@remoteserver.org
Before you can log in to remote servers, you need to:
cd $HOME
mkdir ~/.ssh
chmod 700 ~/.ssh
~/.ssh
cd ~/.ssh
touch config
chmod 600 config
config
cd ~/.ssh
touch authorized_keys
chmod 700 authorized_keys
authorized_keys
cd ~/.ssh
mkdir connections
chmod 700 connections
connections
cd ~/.ssh
mkdir ssh_keys
chmod 700 ssh_keys
ssh_keys
cd ~/.ssh
mkdir pub_keys
chmod 700 pub_keys
pub_keys
At this point, your ~/.ssh
$ ls -lah ~/.ssh
drwx------ 8 user staff 256B Jan 21 18:37 ./
drwxr-xr-x@ 161 user staff 5.0K Jan 21 20:24 ../
-rw-------@ 9 user staff 288B Jan 21 18:37 authorized_keys
-rw-------@ 1 user staff 1.4K Jan 21 19:03 config
drwx------ 2 user staff 64B Jan 22 16:37 connections/
drwx------ 2 user staff 64B Jan 22 16:37 pub_keys/
drwx------ 2 user staff 64B Jan 22 16:37 ssh_keys/
ssh username@123456.server.io
This file acts as the file with predefined options for how to connect through SSH
To modify it, type
open ~/.ssh/config
This will open the config file.
You will now add the global settings
Add this to the config file:
Host *
ControlMaster auto
ControlPath ~/.ssh/connections/%C
ControlPersist 1m
ServerAliveInterval 30
ServerAliveCountMax 10
These settings let you keep the SSH connection alive, and more!
If you're on a MAC and would like to use X11 as well, add these extra lines beneath
XAuthLocation /opt/X11/bin/xauth
AddKeysToAgent yes
UseKeychain yes
Once you have your ~/.ssh/config file setup, you can add your Github info to it.
You you just need to add this below the previous code:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/ssh_keys/github_key
IdentitiesOnly yes
PreferredAuthentications publickey
This will tell git to use the public key github_key, which you will create later.
If you happen to plot on remote servers, you might want to use XQuartz (X11). If yo, you will need to add the following line to the ~/.ssh/config file, below the Host info:
ForwardX11 yes
Your ~/.ssh/config file should look something like this now (scroll):
Host *
ControlMaster auto
ControlPath ~/.ssh/connections/%C
ControlPersist 1m
ServerAliveInterval 30
ServerAliveCountMax 10
XAuthLocation /opt/X11/bin/xauth
AddKeysToAgent yes
UseKeychain yes
## Connects to Github
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/ssh_keys/github_key
IdentitiesOnly yes
PreferredAuthentications publickey
## Connects to a remote Server via SSH
Host server_name
HostName path.to.server
User username
IdentityFile ~/.ssh/ssh_keys/server_key
IdentitiesOnly yes
PreferredAuthentications publickey
ForwardX11 yes
Remember to change server
and path.to.server
with the real values.
server
: Server to which you want to connectpath.to.server
: URL of the server
$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096
$ Generating public/private rsa key pair.
Enter file in which to save the key (/Users/calder/.ssh/id_rsa): id_rsa_4096
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
$ ls
id_rsa_4096
id_rsa_4096.pub
$ chmod 600 id_rsa*
$ mv id_rsa_4096 ssh_keys/
$ mv id_rsa_4096.pub pub_keys
Now you can add your pair of SSH keys:
ssh-add ~/.ssh/ssh_keys/*
or, if you're on a Mac
ssh-add -K ~/.ssh/ssh_keys/*
If you enter a passphrase, you will need to type that password every time you use the SSH keys (e.g. when connecting to a server). It's common to not create a password, but know that if the private key is lost, anyone can use them.
But they would have to know which server to connect to, which "config" file will provide!
Back to main website: