command snippet

Windows

command snippet/windows

user

ユーザとグループの一覧

cat /etc/passwd
cat /etc/group

sudo ができる管理ユーザの追加の例

sudo useradd -G adm,sudo USERNAME

パスワードの設定

sudo passwd USERNAME

かんたん。

sudo usermod -p PASSWORD_ENCRYPTED USERNAME

自動化にはいい。PASSWORD_ENCRYPTED は

openssl passwd

を実行し、プロンプトに沿ってパスワードを入れると出力できる。
以下は passwd と同じ動き:

sudo usermod -p `openssl passwd` USERNAME

ユーザのログイン名を変更し、ホームディレクトリを引っ越す

sudo usermod -l CHANGE_TO -d /home/CHANGE_TO -m CHANGE_FROM

今のセッションのコマンド履歴を忘れる

unset HISTFILE

文字列のハッシュ値を取得する

 echo -n 'loremipsum' | sha256sum

disk free

df -h

'-h' は 61917736 を 60G とかになおしてくれる。

parted

パーティションの一覧表示

parted -l

未使用スペースを含めて表示

parted
(parted) print free

tar+gzip

ディレクトリの圧縮

tar -cvzf tgzFILE DIRCompressTo

ディレクトリの展開

tar -xvzf tgzFILE

git

force pushed branch の pull

git pull --rebase

直前の commit のハッシュを出力

git rev-parse HEAD
# b90383d07388fe8513e59a6deb1a2391146c6561
git rev-parse --short @
# b90383d07
git rev-parse --short @~2
# hash from 2 commits ago
git rev-parse --short main
# hash of latest commit on main

直前の commit の author の修正

git commit --amend --author="mgmn <mgmnjp@example.com>" --no-edit

直前の amend commit を取り消す (変更を維持)

git reset --soft HEAD@{1}

`git reflog` した結果の `{n}` こ前に HEAD を移動している。

https://stackoverflow.com/questions/1459150/how-to-undo-git-commit-amend-done-instead-of-git-commit

いまのブランチ名を出力

git rev-parse --abbrev-ref @

上流が共通のよそのリポジトリのブランチに追従する

# ローカルのブランチを切る
git branch yosono-fork

# よその分化直前のコミットまで reset する
git reset --hard (SHA1)

# リモートの追加
git remote add yoso https://example.com/yoso/yoso.git
git fetch yoso

# 上流ブランチの設定
git branch --set-upstream-to yoso/master
git pull

ssh

鍵ペアの生成

ssh-keygen  # RSA3072
ssh-keygen -t ed25519

固まったセッションの強制終了

(Enter)
~.

screen

切断

(Ctrl + a)
k

certbot

証明書の取得

certbot --non-interactive certonly --webroot -w /var/www/html -m "mgmnjp@example.com" --agree-tos -d "example.com" 

証明書の取得 (staging server)

certbot --non-interactive certonly --webroot -w /var/www/html -m "mgmnjp@example.com" --agree-tos -d "example.com" --test-cert

staging server は production server よりも証明書の重複取得の回数制限がかなり緩和されている。

ストアしている証明書の一覧

certbot certificates

ストアしている証明書を削除する

sudo certbot delete --cert-name example.com

取得済みの証明書が「Certificate not yet due for renewal」で再取得できない場合はこれで設定を消すと通るようになる。

openssl

自己証明書の作成

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3650

RSA 鍵からパスワードを削除する

openssl rsa -in key.pem -out key.pem

openssl rsa - Mister PKI
https://www.misterpki.com/openssl-rsa/

curl

verbose

curl -X GET -v https://...

要求ヘッダを指定/追加する

curl --header "Accept: application/json,application/xml" https://...
curl -H "Accept: application/json" -H "Accept-Language: ja" https://...

NTLM 認証をする

curl --ntlm -u user:password https://...

dig

ルートサーバからの反復問い合わせとその応答をすべて表示する

dig @recursive.ns.example.com mgmn.jp +trace

再帰的動作を要求しない問い合わせを行う

デフォルトでは `+recurse` を付加したときと同じ 再帰的動作を要求する問い合わせが行われる。

$ dig a mgmn.jp @authoritative.ns.example.com

; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> a mgmn.jp @authoritative.ns.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1234
;; flags: qr aa rd*1; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1
;; WARNING: recursion requested but not available

`+norecurse` を付加すると、フルリゾルバから権威サーバに行われる問い合わせと同じように、再帰的動作を要求せずに問い合わせる。
キャッシュサーバと権威サーバを兼ねているサーバ*2に問い合わせるときは大切。

dig a mgmn.jp @authoritative.ns.example.com +norecurse
dig a mgmn.jp @authoritative.ns.example.com +norec
thanks to
DNSチュートリアル - JANOG53 Meeting in Hakata
https://www.janog.gr.jp/meeting/janog53/dnsbasic/

回答を複数行表示する

SOA レコードがとくに見やすくなる。

dig mgmn.jp soa +multiline
dig mgmn.jp soa +multi

firewall-cmd

サービス名指定で許可・禁止

sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --remove-service=ssh --permanent

ポート番号指定で許可・禁止

sudo firewall-cmd --add-port=1234/tcp --permanent
sudo firewall-cmd --remove-port=1234/tcp --permanent

Mastodon

下段は development 環境用。

依存関係の更新

bundle && yarn --frozen-lockfile

DB のバックアップ

pg_dump -Fc mastodon_production -f ~/donbak/pg_backup.dump
pg_dump -Fc mastodon_development -f ~/donbak/pg_backup.dump

DB のマイグレーション

RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=development bundle exec rails db:migrate

アセットのリビルド

RAILS_ENV=production bundle exec rails tmp:clear assets:clean assets:precompile
RAILS_ENV=development bundle exec rails tmp:clear assets:clean assets:precompile

public/packs を消した場合は OS 再起動したほうがいいかも
より文明的なやり方をみつけたので mastodon-web の reload だけでよさそう

web と sidekiq の再起動

sudo systemctl daemon-reload && sudo systemctl reload mastodon-web && sudo systemctl restart mastodon-sidekiq
# サービス稼働状態の確認
sudo systemctl | grep mastodon

ユーザの追加

RAILS_ENV=development bin/tootctl accounts create --email EMAIL --confirmed USERNAME

オーナユーザの追加

RAILS_ENV=development bin/tootctl accounts create --role Owner --email EMAIL --confirmed USERNAME

既存ユーザをオーナにする

RAILS_ENV=production bin/tootctl accounts modify --role Owner USERNAME
RAILS_ENV=development bin/tootctl accounts modify --role Owner USERNAME

*1 Recursion Desired フラグ
*2 このような共用サーバは攻撃に弱いため、いまは推奨されていない

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2024-02-27 (火) 15:33:17