MikroserverSetup: Difference between revisions
(Fjernet oppsett av Cadence fra artikkelen siden det dekkes av andre artikler (og stoffet var utdatert). Ryddet opp generelt.) |
mNo edit summary |
||
Line 36: | Line 36: | ||
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. | 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" >> ~. | 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. | 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. |
Revision as of 14:30, 2 May 2020
Setup of connection to mikroservers
This setup process will allow you to connect to the mikroservers with one command without typing any password or host-names.
There are 4 mikroservers at IFT, mikroserver1 through mikroserver4.
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 either mikroserver (mikroserver3 is chosen in this example, but 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
ssh-copy-id USERNAME@mikroserver3.ift.uib.no
You will be prompted your password. After the key is copied, you should be able to login with "ssh USERNAME@mikroserver3.ift.uib.no" without having to enter your password.
Connection aliases
Now that you can login without typing your password, it is also convenient to set up host names 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 short names and specific SSH settings for the connection, such as your username.
Host mikroserver3 HostName mikroserver3.ift.uib.no 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 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 mikroserver3" in the terminal to login to mikroserver3. 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 TTY software PuTTY to enable X11 forwarding.
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 mikroserver3" 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
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:
as server address type:
sftp://mikroserver3/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 "mikroserver3"-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 (ssh mikroserver3)
- 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"