# User Guide - NTU BDSRC EDU System
:::info
- If you encounter any problem, please contact ntubdsrc@ntu.edu.tw
- Change your password as soon as you log into the system. (Check out the User Setup section)
:::
:::danger
Do not modify any other file except it is in your folder.
:::
## Overview
### What is a terminal?
Terminal is a text-based interface allowing us to interact with the operating system. We can perform any task without using the graphical interface, that colorful desktop you usually see on the screen. Different OS provides different name for terminal, you can find it with the following names:
- **macOS**: terminal.app
- **windows**: PowerShell, CMD
- **Linux**: Terminal (right click to open if you are accessing through the desktop)
### How to Access the computing resource?
There are 3 servers you can access in total (node01 is not avaliable to use currently). You can access all the EDU server via the IP address `140.112.176.246`. With this address, you will connect to `master` server by default. To access other servers, you need to specify which port you want to connect to.
:::info
- **Local machine**: The computers you have on hand.
- **Remote machine**: The servers you access via the Internet.
:::

## SSH Connection
SSH is a remote access protocol that allows you to connect any remote device with terminal. The problem with this method is that it does not provide graphical interface like Desktop in Windows.
```shell
# In your terminal:
## SSH Syntax (for accessing master)
ssh <username>@140.112.176.246 -p 2211
## If the terminal keeps yielding some weird failing messages that do not affect the connection
ssh -o LogLevel=ERROR <username>@140.112.176.246 -p 2211
```
:::info
***After you have connected to master***, you can further access to other node if you notice that there are to much user using the same node (your program may run slower than expected).
```shell
# In your terminal: (notice that you have to connect to master first)
## connect to node02
ssh node02
## connect to node03
ssh node03
```
:::
To end the SSH connection, you can type `exit` or use `ctrl-D` or `ctrl-C`
## User Setup
### Change Password
Use `ldappasswd -x -H ldap://192.168.0.11:389 -D "uid=<username>,ou=Student,ou=<KEYWORD>,ou=Courses,dc=BDSRC,dc=edu" -W -S` command and enter the current password to change it. (where <KEYWORD> will be provided to teachers of your courses)
:::danger
***Only change your password from "master"***
:::
### Some Utilities
There are several softwares you can launch on the terminal of the server.
```shell
# Stata17
/homes/source/stata/stata
# Stata19 (new version)
/homes/source/stata19/stata
# Stata19 (new version, large data)
/homes/source/stata19/stata-se
# Python
python3 <filename>.py
# Julia
julia
#R
R
```
To start up the GUI (Graphical User Interface) version, make sure you have install X server in you computer:
* Linux: usually already installed X server
* Mac: install XQuartz
* Windows: it is recommanded to install Mobaxterm as a terminal, since it include X server and remote file system (here is a tutorial for mobaXterm: https://blog.csdn.net/qq_44074697/article/details/118544904)
, or you have to install [VcXsrv](https://blog.csdn.net/luohaitao/article/details/147120849)
```shell
# before using the gui version use "-X" to activate X server at local side
ssh -X <username>@140.112.176.246 -p 2211
ssh -X node02
# Stata17/IC 2GB memory limited
/homes/source/stata/xstata
# Stata19/IC 2GB memory limited (new version)
/homes/source/stata19/xstata
# Stata19 (new version, large data)
/homes/source/stata19/xstata-se
```
### File Access Control
:::danger
Your files might be visible to others. To prevent this, you need to set up access control. However, if your data isn't sensitive, you can choose to ignore this.
:::
3 types of Permission: `r`(read), `w`(write), `x`(execute)
#### Checking File Permissions
```shell
# Example
ls -l test.txt
# Output
-rw-rw-r-- 1 ryan ryan 0 九 2 14:58 test.txt
# or you can use `getfacl`
getfacl <filename>
```
For example a file's permission is `-rw-rw-r--`, you can interpret it as:
- Is it a directory: `-` (it will be `d` if it's a directory)
- Owner: `rw-` (you can read and write)
- Group: `rw-` (people in your group can read and write)
- Others: `r--` (people outside of your group can only read)
:::info
`rw-` can be translated into `110`, which is `6` in decimal value. So the permission of the example above can be represented as `660`. If you want to set the permission as `rwxr-x---`, you can simply type:
```shell
chmod 750 <filename>
```
:::
#### Modify File Permission
```shell
# Syntax
chmod <setting> <target name>
# Example: add execute permission for yourself.
chmod u+x <filename>
# Example: Take away other's rwx permission
chmod o-rwx <filename>
```
#### Modify Directory Permission
```shell
# Syntax
chmod -R <your setting> <dir name>
```
:::info
`u`: you
`o`: others
`g`: users in your group
`+`: add
`-`: remove
`=`: assign
:::
#### Group Control
You might want to share files and directories with your project members. For convenience, you can ask us to create a group for your project by submitting the application https://forms.gle/6Ro9YciS68czZi5E9
##### Group Basics
```shell
# show all the groups you are in
groups
# You might want to switch between the groups
# when you create a new file
newgrp <group name>
# Type exit when finishing your operation for that group
exit
```
If you are the owner of a group, you can add/delete the group member at your own will:
```shell
# add user
gpasswd -a <username> <group name>
# delete user
gpasswd -d <username> <group name>
```
#### Further info on File Permission
- https://www.redhat.com/sysadmin/linux-file-permissions-explained
- https://www.geeksforgeeks.org/how-to-set-file-permissions-in-linux/
## VS Code Remote Editing
You might not want to transfer your file to the remote server every time you modify your codes in your local machine. Therefore, directly editing the files on the remote server through VS Code can be super convenient.
Can go to [VScode official website](https://code.visualstudio.com/download) to download the package that is suitable to your operation system
1. Install extension *"Remote Development"*, *"Remote - SSH"* and "*Remote Explorer*"

2. Open a remote window

3. Connect to Host

4. Add new SSH host > Configure SSH Hosts

5. Choose which file you want to save the configuration (you can choose the first one that appears)

6. Edit the configuration
```shell
# Format for master
Host <master name (Whatever you like)>
HostName 140.112.176.246
User <your user name>
Port 2211
# Format for other nodes
Host <node name (Whatever you like)>
HostName node02
User <your user name>
ProxyJump <master name>
```

7. Establish Connection

8. First time for your connection (choose Linux)

9. type your password

10. open your file system

11. When you are using jupyter notebook (.ipynb file), make sure you select correct kernel to compile your code.

:::info
for the first time you click select kernel, you have to install the extension first.


or

and install extension for python

if you want to use python.
Before using julia, type
```
/opt/julia-1.10.5/bin/julia -e 'using Pkg; Pkg.add("IJulia")'
```
on your terminal to install the needed package.
:::


12. happy coding!

:::info
you can install the package you want in the jupyter notebook cell by
* Python:typing `!pip install <package name>`
* Julia:typing `using Pkg; Pkg.add("<package name>")`
* R:typing `install.packages("<package name>")`
and run them.
:::
## Basic Linux Guide
https://www.geeksforgeeks.org/linux-tutorial/