====== tips ====== ===== sha512でハッシュされたsaltつきパスワードを生成する ===== perl $ perl -e 'print crypt("password", "\$6\$SALTsalt");' $6$SALTsalt$UiZikbV3VeeBPsg8./Q5DAfq9aj7CVZMDU6ffBiBLgUEpxv7LMXKbcZ9JSZnYDrZQftdG319XkbLVMvWcF/Vr/ openssl((1.1.1以降)) $ openssl passwd -6 -salt SALTsalt password $6$SALTsalt$UiZikbV3VeeBPsg8./Q5DAfq9aj7CVZMDU6ffBiBLgUEpxv7LMXKbcZ9JSZnYDrZQftdG319XkbLVMvWcF/Vr/ ===== 正規表現 ===== * [[http://www.kt.rim.or.jp/~kbk/regex/regex.html|正規表現メモ]] * [[https://qiita.com/richmikan@github/items/b6fb641e5b2b9af3522e|どのUNIXコマンドでも使える正規表現]] ===== 開いているポートを確認する ===== ==== netstat ==== $ netstat -an | grep LISTEN tcp4 0 0 *.80 *.* LISTEN ...... pidも見る((freeBSDでは動作しない)) $ netstat -apn | grep LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 31xxx/nginx: worker ...... * -aオプション->現在の全ての接続を表示。指定しないとESTABLISHEDのみ表示 * -pオプション->プロセスIDとプロセス名を表示 * -nオプション->ホスト名で表示せず、IPアドレスで表示する(名前解決しない) ==== lsof ==== ファイル指定 # lsof /var/log/messages COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsyslogd 949 root 1w REG 202,1 161802 266276 /var/log/messages tail 1966 root 3u REG 202,1 161802 266276 /var/log/messages port指定 # lsof -i:80,433 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 16884 root 7u IPv4 8072178 0t0 TCP *:http (LISTEN) nginx 16886 nginx 7u IPv4 8072178 0t0 TCP *:http (LISTEN) ... プロセス名指定 # lsof -c nginx COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 16884 root cwd DIR 202,1 4096 2 / nginx 16884 root rtd DIR 202,1 4096 2 / nginx 16884 root txt REG 202,1 884504 25102 /usr/sbin/nginx ... PID指定 lsof -p 16884 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 16884 root cwd DIR 202,1 4096 2 / nginx 16884 root rtd DIR 202,1 4096 2 / nginx 16884 root txt REG 202,1 884504 25102 /usr/sbin/nginx ... ユーザ指定 # lsof -u user COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 1663 ec2-user cwd DIR 202,1 4096 2 / sshd 1663 ec2-user rtd DIR 202,1 4096 2 / sshd 1663 ec2-user txt REG 202,1 571224 26039 /usr/sbin/sshd ... ===== コマンドを連結 「;」「&」「&&」「||」の違い ===== ==== ;(セミコロン) ==== 前のコマンドが終わり次第、次のコマンドが実行 ==== &(アンパサンド) ==== 前のコマンドの完了を待たない ==== && ==== 前のコマンドがうまく終了した(終了ステータスが0)時に、次のコマンドを実行 ==== || ==== 前のコマンドに失敗(終了コード0以外)したら、次のコマンドを実行 ===== コマンドラインでhash ===== $ echo -n 'hoge' | shasum -a 1 31f30ddbcb1bf8446576f0e64aa4c88a9f055e3c - $ echo -n 'hoge' | shasum -a 256 ecb666d778725ec97307044d642bf4d160aabb76f56c0069c71ea25b1e926825 - $ echo -n "hoge" | openssl sha1 (stdin)= 31f30ddbcb1bf8446576f0e64aa4c88a9f055e3c * -n:改行コードを出力しない * -a:アルゴリズム GNU拡張 $ openssl passwd -1 -salt "SALTsalt" "test" $1$SALTsalt$CEvzkj.qgOcLTyU2B5Kg3. $ openssl passwd -apr1 -salt "SaltsALT" "p@ssw0rd" $apr1$SaltsALT$51lBhVKD0vAdzxUx/rXqY/ perl $ perl -e 'print crypt("test", "\$6\$SALTsalt");' $6$SALTsalt$gH47I0mRGadJVVlIpeTxVlYw.SjkPOZ7lJoGkqOyhyeUJ7PV5QWuYpIG6D5ggew6RXLpl1eA72TpgX5pGDpr/. python $ python -c "import crypt, getpass, pwd; print crypt.crypt('test','\$6\$SALTsalt\$')" $6$SALTsalt$gH47I0mRGadJVVlIpeTxVlYw.SjkPOZ7lJoGkqOyhyeUJ7PV5QWuYpIG6D5ggew6RXLpl1eA72TpgX5pGDpr/. ===== UUID生成 ===== $ uuidgen -r -r を付けないとランダム(UUID Version4)にならないので注意(@FreeBSD) ===== ダミーファイルを作る ===== 10Mbyte # dd if=/dev/zero of=10M.txt bs=1M count=10 Linuxならこれも((ddより早い)) # fallocate -l 10M 10M.txt ===== SSHでパイプしつつデータ転送 ===== cat hoge.txt | ssh host " cat > /tmp/huga.txt" ===== diff コマンドで横並びで表示したい ===== diff -y path/to/file1 path/to/file2 変更行のみを表示したい diff -y --suppress-common-lines path/to/file1 path/to/file2 ===== Gitでcheckout時にPermission Denied ===== どうも、SourceTreeかTortoiseGitがつかんで離していない模様。\\ 再起動で治った ===== コミット時に書いてほしいこと ===== * どのような変更ですか? * この変更によって,どんなことが起きますか? * なぜその変更が必要でしたか? * 参考URLなど(あれば) ===== tmpwatchコマンド ===== 使い所 * ある一定の時間を過ぎたファイルやディレクトリを削除したい時 * 一時ファイルを定期的に削除したい時 * 定期的に◯時間アクセスがないログファイルとかを削除したい時 ===== ハードウェア情報 ===== dmidecodeが便利((要インストール)) メモリ情報 # dmidecode --type memory Memory Device Array Handle: 0x1000 Error Information Handle: Not Provided Total Width: 72 bits Data Width: 64 bits Size: 2048 MB Form Factor: DIMM Set: 4 Locator: DIMM_A7 Bank Locator: Not Specified Type: DDR3 Type Detail: Synchronous Registered (Buffered) Speed: 1333 MT/s Manufacturer: 00CExxxxxxxxx Serial Number: 83xxxxxx Asset Tag: 02113611 Part Number: M393xxxxxxxxx-xxx Rank: 2 CPU情報 # dmidecode --type processor Processor Information Socket Designation: CPU1 Type: Central Processor Family: Xeon Manufacturer: Intel Signature: Type 0, Family 6, Model 44, Stepping 2 Flags: FPU (Floating-point unit on-chip) ...... Version: Intel(R) Xeon(R) CPU L5639 @ 2.13GHz Voltage: 1.2 V External Clock: 5860 MHz Max Speed: 3600 MHz ===== 各種サーバの設定ファイルの書式チェックの方法 ===== ==== apache ==== /usr/local/sbin/httpd -S or apachectl configtest ==== nginx ==== # nginx -t ==== postfix ==== # postfix check 何も出なければOK ==== lighttpd ==== # lighttpd -t -f /usr/local/etc/lighttpd/lighttpd.conf ==== sshd ==== # sshd -t 何も出なければOK ==== dovecot ==== # doveconf -n ==== PHP ==== ==== Rspamd==== rspamadm configtest ===== 換算表(サブネットマスク) ===== ^IPアドレス数^サブネットマスク^ビットマスク^ |1|255.255.255.255|32| |2|255.255.255.254|31| |4|255.255.255.252|30| |8|255.255.255.248|29| |16|255.255.255.240|28| |32|255.255.255.224|27| |64|255.255.255.192|26| |128|255.255.255.128|25| |256|255.255.255.0|24| |512|255.255.254.0|23| |1,024|255.255.252.0|22| |2,048|255.255.248.0|21| |4,096|255.255.240.0|20| |8,192|255.255.224.0|19| |16,384|255.255.192.0|18| |32,768|255.255.128.0|17| |65,536|255.255.0.0|16| |131,072|255.254.0.0|15| |262,144|255.252.0.0|14| |524,288|255.248.0.0|13| |1,048,576|255.240.0.0|12| |2,097,152|255.224.0.0|11| |4,194,304|255.192.0.0|10| |8,388,608|255.128.0.0|9| |16,777,216|255.0.0.0|8| |33,554,432|254.0.0.0|7| |67,108,864|252.0.0.0|6| |134,217,728|248.0.0.0|5| |268,435,456|240.0.0.0|4| |536,870,912|224.0.0.0|3| |1,073,741,824|192.0.0.0|2| |2,147,483,648|128.0.0.0|1| |4,294,967,296|0.0.0.0|0|