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.

SSH

  • Generate SSH key pairs: ssh-keygen, ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • Show SSH private key: cat ~/.ssh/id_rsa
  • Show SSH public key: cat ~/.ssh/id_rsa.pub
  • 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/id_rsa.pub to “Deploy Keys” in GitHub
  2. Test the connection using sudo -u {user} ssh -T git@github.com
  3. Set the remote: git remote set-url origin git@github.com:{github_id}/{repo_name}.git

Processes

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

MySQL

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

Screen

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

GPG

  • 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

Git

GitHub seems to recogonize you by user.email

  • git config user.name
  • git config user.email

Anaconda

Environments

  • 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

Apache

  • 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

</Directory>


# Jekyll

## gem镜像
```bash
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
gem sources -l
https://gems.ruby-china.com

# 确保只有 gems.ruby-china.com

bundle镜像

bundle config mirror.https://rubygems.org https://gems.ruby-china.com

解决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

Anaconda的Tuna源

conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config –set show_channel_urls yes

NUS mirror

deb http://download.nus.edu.sg/mirror/ubuntu/ YOUR_UBUNTU_VERSION_HERE main 
deb-src http://download.nus.edu.sg/mirror/ubuntu/ YOUR_UBUNTU_VERSION_HERE main 

Tensorflow

Install pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

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 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo apt install ./cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-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=7.2.1.38-1+cuda9.0 \
    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 #没有输出,即说明安装成功

Trim

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

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

#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG

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

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

Shadowsocks

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 - https://repo.fortinet.com/repo/ubuntu/DEB-GPG-KEY | sudo apt-key add -

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

deb [arch=amd64] https://repo.fortinet.com/repo/ubuntu/ xenial multiverse

Update package lists

sudo apt-get update

Install FortiClient

sudo apt install forticlient

Ubuntu 18.04 LTS

Install gpg key

wget -O - https://repo.fortinet.com/repo/ubuntu/DEB-GPG-KEY | sudo apt-key add -

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

deb [arch=amd64] https://repo.fortinet.com/repo/ubuntu/ /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

https://developer.nvidia.com/cuda-downloads

GPG

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/id_rsa.pub $ ssh-agent /bin/sh $ ssh-add $yourkey

Tell Git About Your GPG signing Key