This post is just for personal convenience while using ubuntu server. Some configurations and tools below are very useful but easy to forget. So I write this post to record those command lines.
目录 How to build an ubuntu server quickly docker some basic tools openssh zsh conda pip git github cheatsheet for ubuntu nginx tmux ubuntu desktop
How to build an ubuntu server quickly When I create a new account, this order will help me to handle the blank ubuntu server very fast.
docker 1 2 3 4 5 6 7 8 9 10 11 12 13 docker ps -a docker images docker stop <docker container name> docker rm -f <container id > docker run --name wgt-pytorch --runtime=nvidia -itd -v /home/wuguotong/wgt-pytorch:/wgt-pytorch -p 3320:22 -p 3321:3321 --shm-size 8G pytorch/pytorch:1.9.0-cuda11.1-cudnn8-devel docker start wgt-pytorch docker exec -it wgt-pytorch /bin/bash
Before use apt-get install, you should:
For sudo and vim
1 apt-get install sudo vim curl git htop
openssh Change root password
Install openssh
1 2 3 4 5 sudo apt-get install openssh-server sudo /etc/init.d/ssh start ps -e | grep ssh
Then modify ssh configuration, use vim /etc/ssh/sshd_config
, change PermitRootLogin no
to PermitRootLogin yes
, restart ssh:
1 sudo /etc/init.d/ssh restart
On your remote computer, the ssh configuration should be like this:
1 2 3 4 5 Host sustech-root HostName 10.20.47.117 User root ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p Port 3320
Then you can use vscode to connect remote
zsh First change the apt source, reference on aliyun mirror help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
Install zsh
1 2 sudo apt-get install zsh chsh -s /bin/zsh
Install oh-my-zsh
1 sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh) "
conda Before use, make conda useful for your shell env:
1 2 3 4 conda create -n <new name> --clone <base name> conda activate <new name>
Change conda package source, reference on tsinghua mirror help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pip 1 $ pip config set global.index-url https://mirrors.sustech.edu.cn/pypi/simple
git Initialize the configuration when first using git
1 2 git config --global user.name "XXX" git config --global user.email "XXX@email.com"
github Add ssh key to github, ref github page
Check the directory listing to see if you already have a public SSH key.
Generating a new SSH key
1 $ ssh-keygen -t ed25519 -C "your_email@example.com"
Copy the public key, and add it to github website
1 $ cat ~/.ssh/id_ed25519.pub
Test ssh connection
1 2 $ ssh -T git@github.com
cheatsheet for ubuntu This part records some important tools and command lines.
nginx nginx简单配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 server { listen 80; server_name your_domain_name; rewrite ^(.*)$ https://$host$1 ; index /root/guotongwu.github.io/index.html; location / { proxy_pass http://127.0.0.1:4000; } error_page 404 /root/guotongwu.github.io/404.html; } server { listen 443 ssl; server_name your_domain_name; root html; index /root/guotongwu.github.io/index.html; ssl_certificate pem_path; ssl_certificate_key key_path; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; location / { root html; index /root/guotongwu.github.io/index.html; proxy_pass http://127.0.0.1:4000; } }
nginx重启服务
tmux 参考:阮一峰网络日志
基本操作
1 2 3 4 5 6 7 8 9 10 11 tmux new -s <session name> tmux detach tmux attach -t <session name> tmux kill-session -t <session name> tmux rename-session -t <session number> <new name> Ctrl+b, $
快捷键
1 2 3 4 5 6 7 8 9 10 11 12 13 14 Ctrl+b %:划分左右两个窗格。 Ctrl+b ":划分上下两个窗格。 Ctrl+b <arrow key > :光标切换到其他窗格。<arrow key > 是指向要切换到的窗格的方向键,比如切换到下方窗格,就按方向键↓。 Ctrl+b ;:光标切换到上一个窗格。 Ctrl+b o:光标切换到下一个窗格。 Ctrl+b {:当前窗格与上一个窗格交换位置。 Ctrl+b }:当前窗格与下一个窗格交换位置。 Ctrl+b Ctrl+o:所有窗格向前移动一个位置,第一个窗格变成最后一个窗格。 Ctrl+b Alt+o:所有窗格向后移动一个位置,最后一个窗格变成第一个窗格。 Ctrl+b x:关闭当前窗格。 Ctrl+b !:将当前窗格拆分为一个独立窗口。 Ctrl+b z:当前窗格全屏显示,再使用一次会变回原来大小。 Ctrl+b Ctrl+<arrow key > :按箭头方向调整窗格大小。 Ctrl+b q:显示窗格编号。
窗口操作
1 2 3 4 5 6 7 8 9 10 11 tmux new-window -n <window name> Ctrl+b c tmux select-window -t <window name> Ctrl+b p Ctrl+b n Ctrl+b w tmux rename-window <new-name> Ctrl+b ,
tmux设置
ubuntu desktop 默认使用TCP协议,需要放行5901端口,参考腾讯云文档
1 2 3 apt-get update apt install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal ubuntu-desktop apt-get install tightvncserver
启动服务,设置密码
更改配置文件:~/.vnc/xstartup
1 2 3 4 5 #!/bin/sh export XKL_XMODMAP_DISABLE=1export XDG_CURRENT_DESKTOP="GNOME-Flashback:GNOME" export XDG_MENU_PREFIX="gnome-flashback-" gnome-session --session=gnome-flashback-metacity --disable-acceleration-check &
重启
1 2 vncserver -kill :1 vncserver -geometry 1280x720 :1