CLI command / 常見 CLI 指令

Published:
Last modified:
Let’s Encrypt

安裝指令

# For macOS
$ brew install letsencrypt

# For Ubuntu
$ apt install certbot

手動產生憑證(可用於驗證 Private IP 或無法安裝 agent 的主機上)
$ certbot certonly --manual --config-dir ~/Desktop/letsencrypt --work-dir ~/Desktop/letsencrypt --logs-dir ~/Desktop/letsencrypt --preferred-challenges dns

自動產生憑證(用於外網可以直接連線到 agent 的主機上)
$ certbot certonly --standalone -n --agree-tos --email 你的電子信箱 --preferred-challenges http -d 你的網域

關閉 SSH 密碼登入
# /etc/ssh/sshd_config

PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no
產生 SSH key
# Ed25519 algorithm
ssh-keygen -t ed25519 -C "[email protected]"

# Legacy system
ssh-keygen -t rsa -b 4096 -C "[email protected]"

Github的教學


用 GPG 簽署 GIT COMMIT
# 顯示自己有哪一些 GPG Keys 
gpg --list-keys 

# 匯出自己的公鑰並上傳到 Github 上 (https://github.com/settings/keys)
gpg --armor --export 你的KEY_ID

# 在 git 設定以下參數來完成

git config --global user.signingkey 你的KEY_ID
git config --global commit.gpgSign true 
git config --global tag.gpgSign true

medium上的教學


ESXi 重起管理服務
/etc/init.d/hostd restart
/etc/init.d/vpxa restart

Docker 清理
$ docker system prune -a
$ docker image prune -a

# Remove unused volumes
$ docker volume ls -qf dangling=true | xargs -r docker volume rm

Openssl 相關指令

用 ffmpeg 合併影片
#clips.txt
file 'first.mp4'
file 'second.mp4'
...
ffmpeg -f concat -i clips.txt -c copy output.mp4

掛載 NFS 磁碟
#掛載
sudo mount -t nfs 192.168.1.21:/DATA   /Users/henryyang/Desktop/NAS_DATA
#ESXi 掛載
esxcfg-nas -a -o 1192.168.1.21 -s /DATA NAS_DATA

用 wget 砍站
#完整指令
wget --mirror --page-requisites --convert-links --directory-prefix ./  https://example.com/
#簡寫指令
wget -mpkP ./  https://example.com/

刪除 Gitlab Rack Attack Ban 的 IP
#查目前所被 Ban 的 IP
grep "Rack_Attack" /var/log/gitlab/gitlab-rails/auth.log

#進入 Redius 刪除該 IP
/opt/gitlab/embedded/bin/redis-cli -s /var/opt/gitlab/redis/redis.socket
del cache:gitlab:rack::attack:allow2ban:ban:<ip>

參考資料:https://docs.gitlab.com/ee/security/rack_attack.html


Firefox 開啟強制 https 模式
偏好設定 -> 隱私權與安全性 -> 純 HTTPS 模式 -> 在所有視窗都開啟純 HTTPS 模式

ln -s <要被連的真實資料夾> <欲建立進入點的虛擬資料夾>

tar 指令

https://blog.gtwang.org/linux/tar-command-examples-in-linux-1/


把 Git Repo 搬移到另外一個全新的 Repo 中
cd existing_repo
git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git lfs fetch --all
git pull --all
git remote rename origin old-origin
git remote add origin [email protected]:traget/newrepo.git
git push -u origin --all
git push -u origin --tags

查詢當下目錄中各資料夾的大小
du -sh /<PATH>/* | sort -rn


Henry Yang© 2020 ·