August 25, 2022

My Ubuntu/Mac Command Cheatsheet

This is a simple Ubuntu command cheatsheet for myself.

GPU

$ nvidia-smi
Thu Jun 22 11:28:07 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.116.04   Driver Version: 525.116.04   CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:67:00.0 Off |                  Off |
|  0%   48C    P8    29W / 450W |   3997MiB / 24564MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A     43171      C   python3                          3994MiB |
+-----------------------------------------------------------------------------+

File System

OS

Python

Change pip source:

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
Writing to /home/sedy/.config/pip/pip.conf

VPN

Get link from https://airtcp6.com/

mkdir clash
cd clash
wget https://github.com/Dreamacro/clash/releases/download/v1.18.0/clash-linux-amd64-v1.18.0.gz
gzip -d clash-linux-amd64-v1.18.0.gz
mv clash-linux-amd64-v1.18.0 clash
chmod +x clash
wget -O config.yaml https://airchats.xyz/link/xxlFHIZsFzxkBaBHlapx?clash=1
./clash -d .

SFTP

https://linuxhint.com/setup-sftp-server-ubuntu/

sudo apt install ssh
sudo vim /etc/ssh/sshd_config

add the following to the end of the file:

Match group sftp
ChrootDirectory /home
X11Forwarding no
AllowTcpForwarding no

ForceCommand internal-sftp will disable SSH, which should not be included.

restart, add group, add/modify user, change permission

sudo systemctl restart ssh
sudo addgroup sftp
sudo useradd -m new_user_john -g sftp
sudo passwd new_user_john
sudo usermod -a -G sftp existing_user_tom
sudo chmod 700 /home/new_user_john
sudo chmod 700 /home/existing_user_tom/

Use FileZilla to connect.

PS. The featured image for this post is generated using Stable Diffusion, whose full parameters with model link can be found at Takin.AI.

Mac

add environment variables: vim ~/.bash_profile`

add to file: export OPENAI_API_KEY=sk-xxx`

View environment variables: printenv

Process