使用证书安全快捷的连接SSH服务

经常使用ssh连接服务器的朋友,有时为了安全可能ssh还使用了非默认端口(22),这样每次使用密码登录时,都得按照如下的命令来连接服务器。这样显得有点不方便,因此推荐将密码设置复杂难以回溯,然后使用证书的形式来登录ssh服务器,免去了每次使用密码的麻烦。只要你把证书妥善保管,就会安全如初。 ssh user@hostname -p223 本地生成证书 首先使用ssh-keygen命令在本地生成证书,为了方便使用未设置证书密码。 $ ssh-keygen Generating public/private ed25519 key pair. Enter file in which to save the key (~/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in ~/.ssh/id_ed25519 Your public key has been saved in ~/.ssh/id_ed25519.pub The key fingerprint is: SHA256:Kcd0LM......Vams1XJA user@op36 The key's randomart image is: +--[ED25519 256]--+ | cef+.=.. | | ..oEo+.X | | aaaa+o O | | obbbb= B | |cccccc= S . | |dddd + . | |O w | | o | | | +----[SHA256]-----+ 设置SSH服务 使用scp或者其他方法将本地的public key文件~/.ssh/id_ed25519.pub上传至服务器。 ...

一月 9, 2025 · JQX

完全删除Docker

在使用了docker一段时间后,会发现系统上各种容器乱七八糟,启动的,未启动的,正常运行的,异常的,搞得人不胜其烦。 下面是一次完全删除docker容器并删除docker本身的实例,可以完美解决以上问题。 查询并停止/删除当前运行容器 ➜ ~ docker ps -aq 80bb62721c12 # 停止当前运行容器 ➜ ~ docker stop $(docker ps -aq) 80bb62721c12 # 删除当前运行容器 ➜ ~ docker rm $(docker ps -aq) 80bb62721c12 删除所有image镜像 ➜ ~ docker rmi $(docker images -q) Untagged: traffmonetizer/cli_v2:latest Untagged: traffmonetizer/cli_v2@sha256:4fc48893746664471a1c386efabb5eba0537955fe5ecae871ed4a5e5c33ecf03 Deleted: sha256:3f82fd6f8f4f5ae49cf715a45db4abb3c0bef25be4d351ebe82e747f8641dd0b Deleted: sha256:d732b5c154d947acd46254d7c729eea712f5dd3e0518884a50cc4ada4da9706d Deleted: sha256:037fbfa145577a9bc6472afdf57979ff128102d42806eebc4dcdbc7eb0c91ff5 Deleted: sha256:e44bc785a3f33dea2990cff187bc1c2b7fea4fa9dfa24a6c3ad3e4c149e7aa80 Deleted: sha256:aa0a4b16279d7f4e301aa29ff8bb3fb2e5eaf2417e8119bd3c92f99da975d674 Deleted: sha256:54d0ead5d2a5dd2e830b333508445bc7e9cbed60b1ec4091d667c71349a9b31c Deleted: sha256:bd00ba4d604e3a30bba51756da10622d2242a8540dc03a46a07584575d736590 Deleted: sha256:d4fc045c9e3a848011de66f34b81f052d4f2c15a17bb196d637e526349601820 卸载docker ➜ ~ apt purge docker-ce Reading package lists... Done Building dependency tree... Done Reading state information... Done The following package was automatically installed and is no longer required: pigz Use 'apt autoremove' to remove it. The following packages will be REMOVED: docker-ce* 0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded. After this operation, 109 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 64321 files and directories currently installed.) Removing docker-ce (5:27.2.0-1~debian.12~bookworm) ... (Reading database ... 64312 files and directories currently installed.) Purging configuration files for docker-ce (5:27.2.0-1~debian.12~bookworm) ... ➜ ~ apt purge docker-ce-cli Reading package lists... Done Building dependency tree... Done Reading state information... Done The following package was automatically installed and is no longer required: pigz Use 'apt autoremove' to remove it. The following packages will be REMOVED: docker-ce-cli* 0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded. After this operation, 40.9 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 64310 files and directories currently installed.) Removing docker-ce-cli (5:27.2.0-1~debian.12~bookworm) ... Processing triggers for man-db (2.11.2-2) ... ➜ ~ apt purge docker-ce-rootless-extras docker-buildx-plugin Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: libslirp0 pigz slirp4netns Use 'apt autoremove' to remove them. The following packages will be REMOVED: docker-buildx-plugin* docker-ce-rootless-extras* 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded. After this operation, 102 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 64111 files and directories currently installed.) Removing docker-buildx-plugin (0.16.2-1~debian.12~bookworm) ... Removing docker-ce-rootless-extras (5:27.2.0-1~debian.12~bookworm) ... ➜ ~ apt purge docker-compose-plugin Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: libslirp0 pigz slirp4netns Use 'apt autoremove' to remove them. The following packages will be REMOVED: docker-compose-plugin* 0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded. After this operation, 63.3 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 64102 files and directories currently installed.) Removing docker-compose-plugin (2.29.2-1~debian.12~bookworm) ...

八月 29, 2024 · JQX

30个帮你提高效率的BASH别名

alias其实就是一个命令的快捷方式,为了将复杂的命令简化成简洁的样子。比如我们常用的ll命令其实就是ls -l命令的alias,这里的ll就是一个alias。 显示alias 使用alias显示当前所有别名,默认情况下将显示当前用户定义的所有alias $ alias alias ..='cd ..' alias ipython='winpty ipython.exe' alias ll='ls -l' alias ls='ls -F --color=auto --show-control-chars' alias ts='date +%s' 定义新的alias 定义新的alias方法如下: alias 名称=值 alias 名称='命令' alias 名称='命令 参数1 参数2' alias 名称='/路径/脚本' alias 名称='/路径/脚本.pl 参数1' 我们常用clear命令来清屏,但每次输入clear有点长,那么就可以为其定义一个简洁的alias。 alias c='clear' 通过以上操作,就为clear命令定义了一个名为c的alias,那么下次输入c命令就相当于执行了clear命令。 提示:可以将alias定义添加到~/.bashrc文件中以保证每次重启都会生效。 临时禁用alias 对于已经定义的alias可以使用以下方法临时禁用。 ## 命令完整目录 /usr/bin/clear ## 使用反斜杠忽略alias \c ## 使用/bin/ls命令并忽略ls的alias command ls 删除alias 想要删除已经定义的alias,就需要使用unalias命令,使用实例如下: ## 使用alias $ ll total 10 -rw-r--r-- 1 bbq 197121 411 Jun 10 2023 id_ed25519 -rw-r--r-- 1 bbq 197121 96 Jun 10 2023 id_ed25519.pub -rw-r--r-- 1 bbq 197121 1957 Aug 14 18:36 known_hosts -rw-r--r-- 1 bbq 197121 1109 Aug 6 15:23 known_hosts.old ## 删除alias $ unalias ll ## 提示alias不存在了 $ ll bash: ll: command not found 提示:如果你将alias添加到~/.bashrc文件中,记得也要删除。 ...

八月 19, 2024 · JQX

Bash读取CSV 文件

CSV文件是使用逗号作为分隔符的文本文件,CSV文件以纯文本格式存储数据,文件的每一行都是一条数据记录。 我们可以使用bash中的while循环来读取CSV文件。IFS变量设置分隔符为,(逗号)。read命令读取每一行并将数据存储到每个字段中。 一个简单的实例 st.sh文件内容如下: while IFS=, read -r fd1 fd2 do echo "$fd1 and $fd2" done < input.csv 我们来运行下st.sh试试: alair@op36 MINGW64 ~/Documents $ cat input.csv bob,18 alair,23 kim,32 alair@op36 MINGW64 ~/Documents $ sh ./st.sh bob and 18 alair and 23 kim and 32 处理丢失的字段 #!/bin/bash missing=false while IFS=, read -r fd1 fd2 do if [ "$fd1" == "" ] then echo "field1 is empty or no value set" missing=true elif [ "$fd2" == "" ] then echo "field2 is empty or no value set" missing=true else echo "$fd1 and $fd2" fi done < input.csv if [ $missing ] then echo "WARNING: Missing values in a CSV file. Operation failed!" exit 1 else echo "CSVfile read successfully!" fi bash解析csv文件 再来一个复杂点的实例。 ...

六月 11, 2023 · JQX