In this article, I list some procedures I do when setting up new Linux server account. They’ll be helpful in the later development stages.
1. Change the default shell
This step is optional. Sometimes the default shell in the machine is merely sh
. We can change it to other better shells like bash
, zsh
, for easier use.
1.1 Show the current shells
You can display the current shell name by either the following commands:
1 | echo $0 |
1.2 Get all available shells
To check what shells are installed, type the following commands:
1 | cat /etc/shells |
1.3 Change the default shell
Use the chsh
(change shell) command to change the shell, with -s
flag:
1 | chsh -s /bin/bash |
Then type the password of the login account (The password is hidden, just type it, and press Enter). Finally, you can quit the shell, and restart it once. You’ll see the new shell.
2. Install conda
Python environment is very essential in my workflow, especially in deep learning. Please refer to the official docs:
https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html
3. Setup ssh key (password-free login)
Modified from the blog here.
(Replace {KeyName}
to any name you like)
3.1. Generate SSH Key Pair on Your Local Machine
(macOS Users please do the following)
1 | ## Execute the following commands on your LOCAL machine |
To check if you make it right, type the following command and you should see a string as the output.
1 | cat ~/.ssh/{KeyName}.pub |
(Windows Users please do the following)
1 | ## Execute the following commands on your local machine |
To check if you make it right, double click the key file (C:\Users\{UserName}\.ssh\{KeyName}.pub
) to view it and you should see a string.
Notes:
- The commands above are executed on your own computer, instead of the server.
- It is fine to use the SSH key file generated before (eg. id_rsa.pub), if you have.
- ssh-keygen will ask you to set a paraphrase, which improves the security of using SSH key authentication. Type “Enter” for no paraphrase.
Parameters for ssh-keygen command explanation:
- -t: type for ssh key generation. Here we use rsa
- -b: bits
- -f: name of your ssh key file. You are recommended to set this parameter in case it
is conflict with the ssh key file you generated before. - -C: comments to distinguish the ssh key file from others
3.2. Transfer Your SSH Public Key File to the Server
We use the scp
command to transfer the public key generated in the former step to the server.
~/.ssh/{KeyName}.pub
is the public key you just generated. {Your Account Name}@{Server ip}
is your server account name and ip address.
1 | ## Execute the following commands on your LOCAL machine |
Notes:
- This command will ask you for password for data transfer. Please make sure that you type in the correct password. If you are Windows user and you want to copy & paste the password for convenience, try “Ctrl + Shift + V” if you fail to paste the password with “Ctrl + V”.
3.3. Configure authorized_keys on the Server
1 | ## Login the server with password. Do this step in locally to establish a ssh connection |
To check if you make it right, execute the following command and you should see a string as the output that is the same as in Step-1.
1 | cat ~/.ssh/authorized_keys |
3.4. Prepare for SSH Connection with Key Authentication
Add the following content to ~/.ssh/config
(In windows, it’s C:\Users\{UserName}\.ssh\config
) file on your LOCAL machine:
1 | Host {Any Name You Like} |
Notes:
- It is recommended to configure with the Remote SSH extension on VS Code. Please refer to Remote Development using SSH for more information.
3.5. Login the Server Password-free with SSH key Authentication
1 | ssh {Your Account Name}@{Server ip} |
or
1 | ssh {Your Account Name}@{Any Name You Like} # above in Sec. 4 |
or
1 | ssh {Any Name You Like} # above in Sec. 4 |
4. Set some alias
Alias convenient us typing some common commands.
Add the following to the end of ~/.bashrc
:
1 | alias cf="ls -l | grep "^-" | wc -l" |
The first alias, cf
means count files, can count number of visible files (excluding directories) under the current working directory.
The second alias, ns
is short for nvidia-smi
to check for the GPU information.
The third alias py
is short for python
.
The fourth alias act
can be used like act py39
(activate the conda py39
environment)
5. Configure the CUDA compiler version
This step is optional. If you want to compile some PyTorch operators locally, you should set the nvcc
version same to the PyTorch runtime version.
Add the following to the end of ~/.bashrc
:
1 | export PATH=/usr/local/cuda-11.1/bin:$PATH |
Change the CUDA directory (/usr/local/cuda-11.1
above) to the one you actually want to use. For example, the PyTorch is compiled under cuda-11.3
, you probably want to use nvcc
with cuda-11.x
, but not cuda-10.2
.
6. ~/.bashrc template
1 | # path to some executable |