Command Archive


So many commands to remember and Google… Might as well create an archive for them~

For now it covers SSH, processes, MySQL, screen, GPG, Anaconda.


  • Generate SSH key pairs: ssh-keygen, ssh-keygen -t rsa -b 4096 -C ""
  • Show SSH private key: cat ~/.ssh/id_rsa
  • Show SSH public key: cat ~/.ssh/
  • Add SSH public key to remote server: ssh-copy-id -i ~/.ssh/mykey user@host (mykey is the filename that ssh-keygen asked, by default is id_rsa)
  • Login via ssh: ssh -i ~/.ssh/mykey user@host

We can always use [-p port] command to specify which port to connect.

ssh -?

  • -T: Disable pseudo-terminal allocation.
  • -t: Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

Using Git via SSH

  1. Copy the result of cat ~/.ssh/ to “Deploy Keys” in GitHub
  2. Test the connection using sudo -u {user} ssh -T
  3. Set the remote: git remote set-url origin{github_id}/{repo_name}.git


  • Show processes containing {name}: ps -ef | grep {name}
  • Kill a process with PID: kill {pid}
  • Kill all processes with {name}: pkill -f {name}


  • Setup: mysql_secure_installation
  • Login: mysql -u {username} -p


Outside a screen session

  • Create a session: screen [-S {name}]
  • Reattach a session: screen -r {name}
  • Reattach if possible otherwise create a new one: screen -R {name}
  • Show screen sessions: screen -list

Inside a screen session

Press control + A first to enter screen command mode.

  • c: create a new screen
  • p: previous screen
  • n: next screen
  • d: detach screen


  • Generate a GPG Key: gpg --full-generate-key
  • For older versions, use gpg --default-new-key-algo rsa4096 --gen-key
  • List GPG keys: gpg --list-secret-keys --keyid-format LONG

The GPG key ID is the string after sec + [encryption method] /, before date of creation.

  • Prints the GPG key ID, in ASCII armor format: gpg --armor --export [key ID]
  • Edit key: gpg --edit-key [key ID]
  • Create a signed commit: git commit -S -m your commit message


GitHub seems to recogonize you by

  • git config
  • git config



  • show list of env: conda env list or conda info --envs
  • create an env: conda create --name [name] or conda create --name [name] [package_name]=[version] to specify required package(s) (version can be omitted)
  • create an env without default packages: conda create --no-default-packages -n [name] [package_name]
  • install a package to an env: conda install -n [name] [package]
  • activate an env: source activate [name]
  • deactivate: source deactivate (or deactivate in Windows)
  • remove an env: conda env remove --name myenv


  • restart: sudo service apache2 restart

Install Apache

sudo apt update
sudo apt install apache2
sudo ufw app list # check apache is available
sudo ufw allow 'Apache'
sudo systemctl status apache2

Change root directory

cd /etc/apache2/sites-available
vim 000-default.conf
# Edit 'DocumentRoot /path/to/my/project'

If access denied

  1. Open /etc/apache2/apache2.conf
  2. Search for Directory
  3. Change it to ```
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted


# Jekyll

## gem镜像
gem sources --add --remove
gem sources -l

# 确保只有


bundle config mirror.

解决bundle install没有写入权限的问题

sudo chmod 1777 -R /home/leo/.bundle/cache

Install Jekyll

apt install ruby
apt install ruby-dev
gem install bundler
gem install jekyll
bundle exec jekyll new <Your Site>

Install nokogiri

sudo apt install pkg-config sudo apt install zlib1g-dev sudo gem install pkg-config -v “~> 1.1” sudo gem install nokogiri


conda config –add channels conda config –add channels conda config –set show_channel_urls yes

NUS mirror



Install pip

curl -o

Install Tensorflow for GPU

sudo apt update
sudo apt install python3-dev python3-pip
sudo pip3 install -U virtualenv  # system-wide install

virtualenv --system-site-packages -p python3 ./venv
source ./venv/bin/activate  # sh, bash, ksh, or zsh
pip install --upgrade pip

# Add NVIDIA package repository
sudo apt-key adv --fetch-keys
sudo apt install ./cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt update

# Install CUDA and tools. Include optional NCCL 2.x
sudo apt install cuda9.0 cuda-cublas-9-0 cuda-cufft-9-0 cuda-curand-9-0 \
    cuda-cusolver-9-0 cuda-cusparse-9-0 libcudnn7= \
    libnccl2=2.2.13-1+cuda9.0 cuda-command-line-tools-9-0

# Optional: Install the TensorRT runtime (must be after CUDA install)
sudo apt update
sudo apt install libnvinfer4=4.1.2-1+cuda9.0

pip install --upgrade tensorflow
# Verify the install
python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"


sudo gedit /etc/modprobe.d/blacklist.conf 在最后一行添加: blacklist nouveau 之后,执行命令: sudo update-initramfs -u 电脑重启之后执行 lsmod | grep nouveau #没有输出,即说明安装成功


首先在 /etc/cron.daily 目录下创建一个名为 trim 的文件: sudo gedit /etc/cron.daily/trim

往 trim 文件中粘贴如下内容:

echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG

真正执行 Trim 操作的是最后两个命令,要根据实际情况进行修改。因为我的根目录和 home 目录在两个独立的分区,所以在这里使用了两个命令分别执行 fstrim。

最后给 trim 文件加一个可执行权限就可以了: sudo chmod +x /etc/cron.daily/trim


sslocal -c /etc/shadowsocks/shadowsocks.json 
systemctl start privoxy

Install Oracle JDK

sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java9-installer

Install Gnome Desktop

Install Forticlient

Ubuntu 16.04 LTS

Install gpg key

wget -O - | sudo apt-key add -

Add the following line in /etc/apt/sources.list

deb [arch=amd64] xenial multiverse

Update package lists

sudo apt-get update

Install FortiClient

sudo apt install forticlient

Ubuntu 18.04 LTS

Install gpg key

wget -O - | sudo apt-key add -

Add the following line in /etc/apt/sources.list

deb [arch=amd64] /bionic multiverse

Update package lists

sudo apt-get update

Install FortiClient

sudo apt install forticlient

Install OBS

sudo apt-get install ffmpeg
sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt-get update
sudo apt-get install obs-studio

Remove PPAs

sudo add-apt-repository --remove ppa:whatever/ppa

Install CUDA

Install NVIDIA driver

sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update
sudo apt-get install nvidia-xxx


Export GPG private keys

gpg --list-secret-keys
gpg --export-secret-keys $ID > my-private-key.asc
gpg --import my-private-key.asc

clip < ~/.ssh/ $ ssh-agent /bin/sh $ ssh-add $yourkey

Tell Git About Your GPG signing Key