Tags:
create new tag
view all tags

SSH configuration for Mac and Linux

# goto your homedirectory

cd

# create a .ssh directory

mkdir .ssh

# goto .ssh directory

cd ~/.ssh

# create a ssh keypair

ssh-keygen -t rsa -C HPC -f id_rsa_hpc

# enter 2 times a secret word called "passphrase"
# Put this passphrase in a "digital safe" ( p.e. KeepAss see: https://keepass.info/ ) because you need this later on.

# now you created 2 files like this

-rw------- 1 wvanburen users 1766 Mar 27 11:47 id_rsa_hpc
-rw-r--r-- 1 wvanburen users 385 Mar 27 11:47 id_rsa_hpc.pub

# copy and paste the content of the public-key named id_rsa_hpc.pub
# and mail this to hpc-systems@lists.umcutrecht.nl
# After the admins configured your public key on the gateway you can try to login into the hpc gateway by

ssh -i ~/.ssh/id_rsa_hpc -l wvanburen hpcgw.op.umcutrecht.nl
(Give only once a Yes to add the serverkey to your know_hosts file in your .ssh directory)

and enter your selfmade passphrase.
Once you entered the gateway you can continue to log in into the HPC by:

ssh hpcs03
or
ssh hpcs04
and answer with your HPC-password

And you are on the HPC now

You can automate this procedure by creating as ssh-config file. It should be located in your ".ssh" directory, and be called "config".
This is an example.
Copy and save this file in the .ssh directory and call it config.

#############################################
# file : ~/.ssh/config
# date : 20200327
# expl : default ssh config file example 
#############################################

# usage : ssh hpcgw
Host hpcgw
  HostName hpcgw.op.umcutrecht.nl
  User wvanburen
  IdentityFile ~/.ssh/id_rsa_hpc

# usage : ssh gw2hpcs03
Host gw2hpcs03
  HostName hpcs03.op.umcutrecht.nl
  User wvanburen 
  ProxyCommand ssh -i ~/.ssh/id_rsa_hpc -l wvanburen hpcgw.op.umcutrecht.nl nc %h %p 2>/dev/null

# usage : ssh gw2hpcs03X
Host gw2hpcs03X
  HostName hpcs03.op.umcutrecht.nl
  User wvanburen 
  ForwardX11 yes
  ProxyCommand ssh -X -i ~/.ssh/id_rsa_hpc -l wvanburen hpcgw.op.umcutrecht.nl nc %h %p 2>/dev/null

# usage : ssh gw2hpcs04
Host gw2hpcs04
  HostName hpcs04.op.umcutrecht.nl
  User wvanburen 
  ProxyCommand ssh -i ~/.ssh/id_rsa_hpc -l wvanburen hpcgw.op.umcutrecht.nl nc %h %p 2>/dev/null

# usage : ssh gw2hpcs04X
Host gw2hpcs04X
  HostName hpcs04.op.umcutrecht.nl
  User wvanburen 
  ForwardX11 yes
  ProxyCommand ssh -X -i ~/.ssh/id_rsa_hpc -l wvanburen hpcgw.op.umcutrecht.nl nc %h %p 2>/dev/null

# usage : ssh gw2hpct01
Host gw2hpct01
  HostName hpct01.op.umcutrecht.nl
  User wvanburen 
  ProxyCommand ssh -i ~/.ssh/id_rsa_hpc -l wvanburen hpcgw.op.umcutrecht.nl nc %h %p 2>/dev/null

# usage : ssh gw2hpct02
Host gw2hpct02
  HostName hpct02.op.umcutrecht.nl
  User wvanburen 
  ProxyCommand ssh -i ~/.ssh/id_rsa_hpc -l wvanburen hpcgw.op.umcutrecht.nl nc %h %p 2>/dev/null

# usage : ssh hpcs03
Host hpcs03
  HostName hpcs03.op.umcutrecht.nl
  User wvanburen 

# usage : ssh hpcs03X
Host hpcs03X
  HostName hpcs03.op.umcutrecht.nl
  User wvanburen 
  ForwardX11 yes

# usage : ssh hpcs04
Host hpcs04
  HostName hpcs04.op.umcutrecht.nl
  User wvanburen 
  Protocol 2

# usage : ssh hpcs04X
Host hpcs04X
  HostName hpcs04.op.umcutrecht.nl
  User wvanburen 
  ForwardX11 yes

# usage : ssh hpct01
Host hpct01
  HostName hpct01.op.umcutrecht.nl
  User wvanburen 

# usage : ssh hpct02
Host hpct02
  HostName hpct02.op.umcutrecht.nl
  User wvanburen 

# usage : ssh ft_gw2hpct01
#         then start a filezilla session on localhost
# for filetransfer from hpct01 to local machine
Host ft_gw2hpct01
  HostName hpct01.op.umcutrecht.nl
  User wvanburen 
  ProxyCommand ssh -X -i ~/.ssh/id_rsa_hpc -L 8888:hpct01.op.umcutrecht.nl:22 -l wvanburen hpcgw.op.umcutrecht.nl nc %h %p 2>/dev/null

# usage : ssh ft_gw2hpct02
#         then start a filezilla session on localhost
# for filetransfer from hpct01 to local machine
Host ft_gw2hpct02
  HostName hpct02.op.umcutrecht.nl
  User wvanburen 
  ProxyCommand ssh -X -i ~/.ssh/id_rsa_hpc -L 8888:hpct02.op.umcutrecht.nl:22 -l wvanburen hpcgw.op.umcutrecht.nl nc %h %p 2>/dev/null
#########################################

With this oneliner you can replace wvanburen in your own username int the file "~/.ssh/config"

sed -i 's/wvanburen/my_username/' ~/.ssh/config 

for Mac users

sed -i '' 's/wvanburen/my_username/' ~/.ssh/config

and Try

ssh gw2hpcs04 

It will ask for your passphrase on the gateway hpcgw followed by your hpc-password on hpcs04 .

-- Rene Janssen - 2020-03-27

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2020-07-16 - ReneJanssen
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback