日常工具使用小记录 (daily tool usage snippet)
1. 如何上传本地文件至服务器 (how to upload local files to server)
1.1 启动本地server
假设本地目录 C:/your_home/tmp , 该目录下有文件 test.txt
cd c:/your_home/tmp python -m SimpleHTTPServer 8081 // 新开另一个命令窗口 open another cmd tab ifconfig // 找到对应本地分配的内网地址 ,假设为 10.10.20.20 // find your biz IP address assigned from biz network // 登录到服务器server之后拉取本地c:/your_home/tmp/test.txt文件 wget 10.10.20.20:8081/test.txt
1.2 使用scp
下载至本地 scp -P 2222 -i ~/.ssh/your_jump_server.private_key your_account@remote_server_ip:/data/workspace/your_file.txt ./your_dir/ 上传至远端 scp -P 2222 -i ~/.ssh/your_jump_server.private_key ./your_dir/your_file.txt your_account@remote_server_ip:/data/workspace/
1.3 使用mutt发送服务器文件到邮箱
参考指导:https://blog.edmdesigner.com/send-email-from-linux-command-line/
/etc/ssmtp/ssmtp.conf // config sender email account /etc/ssmtp/revaliases // config sender email account echo "Subject: hello" | ssmtp -v your@email.com echo "This is the message body" | mutt -a "your_attachment.1" -a "your_attachment.2" -s "your email subject" -- your@email.com
2. OpenSSL 常用命令 (OpenSSL regular commands)
base64 -D -i base64_signature.txt -o sign.bin // base64文本签名转二进制
openssl dgst -verify pub_cert -keyform PEM -sha256 -signature sign.bin -binary sign_data.txt // 验签
openssl x509 -text -in your_cert.pem // 解析 rsa /ecc 证书 openssl rsa -in your_tls_key -text // 解析rsa私钥 openssl req -text -in request.csr // parse csr 解析CSR文件 openssl x509 -inform der -in your.crt -noout -text openssl x509 -text -noout -inform DER -in your_output.der openssl rsa -in test_pub.pem -pubin -text -noout // parse pub key 解析 openssl ec -in ecc_pri.key -text // 解析ecc私钥 openssl pkcs12 -export -out cert.p12 -in cert.pem -inkey key.pem -passout pass: -nokeys // pem证书转p12格式 openssl pkcs12 -in your.p12 -nokeys -out your.pem // p12格式转pem证书 openssl x509 -inform der -in your.cer -out certificate.pem // cer to pem file
3. 杂项 (Others)
3.1 查找过滤含关键字的文件名
过滤当前目录下所有png后缀的文件名
find . -name "*.png"
3.2 文件内内容查重
test.txt 内容如下:
1
2
2
3
3
a
b
a
执行如下命令:
cat test.txt | sort | uniq -c | sort -nr | more
输出
2 a 2 3 2 2 1 b 1 1
3.3 更换apk镜像repo地址
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
3.4 查看端口占用
netstat -anp | grep 1812
3.5 查找被系统杀掉的进程
dmesg | grep -E -i -B100 'killed process'
3.6 如何生成一个CSR(证书签名申请文件) How to generate a CSR file
参考链接:
https://www.ssl.com/how-to/manually-generate-a-certificate-signing-request-csr-using-openssl/
具体执行:
openssl genrsa -des3 –out your_pair.key 2048 openssl req -config your_pair.cfg -new -key your_pair.key -out your_pair.csr
Example your_pair.cfg:
[ req ] distinguished_name = req_distinguished_name prompt = no
[ req_distinguished_name ] C =AT ST = Test State or Province L = Test Locality O = Organization Name OU = Organizational Unit Name CN = Common Name emailAddress = your_pair_test@email.com
以上。