MikroserverSetup

From ift

Setup of connection to mikroservers

This setup process will allow you to connect to the mikroservers with one command without typing any password or long host names.

SSH key

To login to the server without having to type in your password every time, we can use SSH key pairs. The public key is stored on the server, and you have your private key stored on the UiB login server.

To generate a key, type into the terminal

ssh-keygen  

This will generate the files id_rsa and id_rsa.pub in the folder ~/.ssh, where the latter is the public key that needs to be stored on the server. Copy the key with your identity to any of the mikroservers (since the user environment is shared for each server, this will give you access to all the servers). You can do this manually, but the easiest way is to use the ssh-copy-id utility. NB: Replace USERNAME with your username and mikroserver with the full name of your preferred mikroserver.

ssh-copy-id USERNAME@mikroserver

You will be prompted your password. After the key is copied, you should be able to login with "ssh USERNAME@mikroserver" without having to enter your password.

Connection aliases

Now that you can login without typing your password, it is also convenient to set up aliases for the servers to connect quicker.

To do this, type "gedit ~/.ssh/config" in the terminal. This will open up an empty file, and here you can store shorthand names and specific SSH settings for the connection, such as your username.

Host mikroserver
    HostName mikroserver
    User USERNAME
    Port 22
    ForwardX11 yes
    ForwardX11Trusted yes

Copy and repeat this for each server in the same file, remembering to change the hostname to the full name of the corresponding mikroserver for each entry. ForwardX11 allows you to launch software on the server itself, while displaying the GUI remotely to the lab PC.

After saving the file, you should be able to simply write "ssh mikroserver" in the terminal to login to the chosen mikroserver. Note: If you are attempting to do this step remotely from the UiB login server you need to use a terminal-based editor like Vim, or connect to the login-server with

ssh -Y USERNAME@login.uib.no

to enable the use of graphical editors such as gedit.

Automatic sourcing

There are two main files of sourcing scripts in a Linux environment. One is the file .bashrc, and the other is the file .profile. The difference in these is that the contents of .profile is executed upon login, and .bashrc is executed every time you access the terminal. .bashrc is not sourced to the system by itself upon login, so we need to source .bashrc in .profile manually to use it. This must be done after connecting to one of the mikroservers.

echo "source ~/.bashrc" >> ~/.profile

Scripts can be sourced either within .profile or .bashrc. This will make sure the scripts are loaded every time you log in, so you don't have to do it manually every time.

Accessing the lab software remotely on your private PC

You do not need to set up a VPN to access the lab software from home. By connecting to the mikroservers through the UiB loginserver with X11 forwarding enabled, you can run the software from any network. You can do this directly on Linux/macOS by using SSH in the bash terminal. For Windows, you will need to download the X server software Xming to enable X11 forwarding. This install comes with PuTTY, an SSH client we will use to connect to the Linux based UiB server.

Linux/macOS

The process is the same for both Linux and macOS, except that for macOS you first have to install the X11 server software named XQuartz. Then, simply connect to the login server by typing

ssh -Y USERNAME@login.uib.no

The -Y enables trusted X11 forwarding. From here, you can "ssh mikroserver" just as you would from the lab PC and run software. The steps described above (SSH keys and config files) can be repeated on your personal Linux/macOS PC to simplify connecting to the UiB loginserver. On Linux, the configuration file is located in "~/.ssh/config" just as on the server, while on macOS it is located in "/private/etc/ssh/ssh_config".

Windows

Install Xming and make sure you include PuTTY in the install. Run Xming. It will start minimized, and does not require any setup. When first opening PuTTY, you will be presented with this configuration menu. Fill in the hostname "login.uib.no", but don't connect yet.

Puttylogin.png

Navigate to Connection -> SSH -> X11, and check Enable X11 forwarding, and type in "localhost:0.0" as X display location.

Puttyx11.png

Return to Session, and make sure connection type is set to SSH. Press "Default Settings" and Save to save this configuration for later. Press Open to connect to the server. Enter your username and password, and now you should be in the Linux terminal for the UiB login server. Try to run "gedit" to confirm that you can run a graphical interface. From here you can ssh to the mikroservers and launch software as on the lab computer. Confirm by running gedit on the mikroserver as well to see that you can tunnel X11 through the login server correctly.

Add mikroserver as a folder on your pc

Open up your home folder in Linux and in the bottom left corner click "Connect to Server" as shown in this picture:

ConnectToServer.png

as server address type:

sftp://mikroserver/home/USERNAME

to add your homefolder on mikroserver as a folder on your local PC for easy access to your files (for example the Transistor_operating_point_printer) To store this connection, right click the "mikroserver"-folder and click "Add Bookmark". The next time you just click the bookmark to open it.

Alternative way using scp/secure copy

If for some reason the above doesn’t work you can try this:

  • connect to your mikroserver
  • locate the file you want to copy. i.e /home/USERNAME/picture.jpg
  • type this command
scp picture.jpg USERNAME@login.uib.no:path/to/folder/to/copy/to
  • this will copy the file to your home folder on any UiB machine
  • To copy a folder
scp -r NameOfFolder USERNAME@login.uib.no:path/to/folder/to/copy/to

Troubleshooting

  • Make sure you have restarted your terminal (or source ~/.bashrc) if the commands doesn't work
  • You have to be either connected to the UiB loginserver or run the commands via the computers in the lab to be able to connect to the mikroservers
  • If you are using another shell like zsh or csh the aliases has to be in ~/.zshrc or ~/.cshrc instead of ~/.bashrc
  • Make sure you have replaced all the instances of USERNAME with your usename, i.e "abc0123"