Setting up Linux
Setting up ssh-agent
- Set up GPG-Agent by following the Ubuntu or Debian section.
- Create a new GPG key and an authentication subkey.
- Extract the public key and transfer the public key to the group server.
- Open a new terminal and test if you can SSH to group server without entering a password using the GPG agent:
ssh USER_NAME@server.dept.univ.eduKeep this terminal open so you can access the sample files on the group server for later steps.
Setting up .ssh/config
- On your computer, create a file
~/.ssh/config, copy the sample setup from the group server, and change the placeholders to appropriate values. - Make sure to understand Sharing sessions over a single connection and Host alias. Leave Multi-hop for later when you need it but do keep in mind of this option.
- Verify that you have the correct permissions for
~/.ssh/config.
Transferring SSH setup to another machine
Once you set up ssh and gpg-agent, you can easily transfer the settings to another server:
rsync -avzP ~/.ssh/{config,id_rsa.pub} user@remote.system:.ssh/ # Edit user@remote.system as necessary; e.g. USER_NAME@server.dept.univ.edu
rsync -avzP ~/.gnupg/{gpg-agent.conf,sshcontrol} user@remote.system:.gnupg/
rsync -avzP ~/.gnupg/private-keys-v1.d/* user@remote.system:.gnupg/private-keys-v1.d/Testing SSH setup
Using the terminal that was connected to the group server and kept open, append to the ~/.gnupg/gpg-agent.conf file and test if you can SSH to Expanse without entering a password using the GPG agent and the shorthand host name you set up in ~/.ssh/config:
echo 'allow-loopback-pinentry' >> ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent # first reload the gpg-agent
ssh expanseCustomizing shell
-
.bashrcis a login file that the Bash shell reads whenever it starts. This is where you can put configurations (environment variables, aliases, path amendments, etc.) to customize your Terminal experience. An example of a.bashrcfile is included here. As you become more comfortable with Linux/Unix, you may find you modify this file frequently. - The file should be located in your home directory (
~/), and you need to create it if it does not yet exist. Open and save the file with the editor of your choice. You will not need thesudocommand since this file is now in your home directory and you have write permission. If you use vi, just typevi ~/.bashrcat the prompt. - Use the copy and paste commands to put the following lines into your
.bashrcfile.# Amend environment variables export PATH="$PATH:." # Set prompt PS1='\[\e]2;\w\a\]\u@\h:\[\e[1m\]\w\[\e[0m\]\$ ' # User Specific Aliases umask 077 export CLICOLOR=1 alias edm='emacs --daemon' alias ecl='emacsclient --create-frame' alias enw='emacsclient -nw' alias grep='grep --color' alias less='less -Ri' alias la='ls -ahlF' alias lh='ls -hlF' alias rbak='\rsync -rltDzP --delete --delete-excluded --force' alias rsync='rsync -azP' alias ssh='ssh -Y' os_name=$(uname); if [ $os_name == 'Darwin' ]; then alias top='top -ocpu -Otime -F -R' elif [ $os_name == 'FreeBSD' ]; then alias vi='vim -c "syntax on"'; else alias qm='qstat -u $USER' alias qI='qsub -I -X -V -l nodes=1:ppn=8,walltime=1:00:00 -q devel' alias sm='showq -u $USER' alias sq='squeue -o "%.18i %.9P %.30j %.8u %.2t %.10M %.6D %R"' alias sqm='sq -u $USER' fi alias group-server='ssh username@server.dept.univ.edu'The first section is where modifications to the environment variables go. An example of this is addition to the
PATHused to search for executable commands. In this example, the.adds the working directory to the existing path ($PATH), so any executables you create in whatever directory you are working in can be referenced directly.The next section is the specification for the style of the prompt. This prompt is set to display
username@hostname:/working/directory$in bold font. It also sends the same information into the title bar of the terminal window (either Terminal or X-terminal). This is default behavior on Unix machines, but needs to be specifically configured on Mac machines. Writing information about the hostname and working directory into the title bar helps keep track of multiple windows logged in to multiple machines. For more information on setting prompts in the bash shell, search online for the bash prompt HOWTO.The last section contains user-specified command shortcuts. The long command, shown in quotes, is linked to whatever series of key strokes (preceding the equal sign) you specify in this file. This example includes two list commands,
lh, andla. The–hlFflag list files with information about their size and when they were created. The–aoption lists hidden files (all files that start with.). An aliased SSH connection is created to a remote HPC server. When you paste these lines into your own file, be sure to change ‘username’ to your specific username. You can add your own aliases as they become more useful to you over the course of your research. - Save the file and exit (
:wqor:xfor vi). - Tell the computer to begin reading your new
~/.bashrcsettingssource ~/.bashrc
Comments
Comments powered by Disqus