feat: add chmod.md ssh.md cheatsheet.

This commit is contained in:
jaywcjlove 2022-10-03 02:11:09 +08:00
parent d02f059357
commit 5279d3082e
6 changed files with 530 additions and 1 deletions

View File

@ -32,10 +32,12 @@ Quick Reference
## Linux 命令
[Chmod](./docs/chmod.md)<!--rehype:style=background: rgb(239 68 113/var(\-\-bg\-opacity));-->
[Cron](./docs/cron.md)<!--rehype:style=background: rgb(239 68 68/var(\-\-bg\-opacity));-->
[Git](./docs/git.md)<!--rehype:style=background: rgb(215 89 62/var(\-\-bg\-opacity));-->
[find](./docs/find.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[Sed](./docs/sed.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[SSH](./docs/ssh.md)<!--rehype:style=background: rgb(99 99 99/var(\-\-bg\-opacity));-->
<!--rehype:class=home-card-->
## 其它

266
docs/chmod.md Normal file
View File

@ -0,0 +1,266 @@
Chmod 备忘清单
===
这份快速参考备忘单提供了文件权限的简要概述,以及 chmod 命令的操作
入门
--------
### 语法
```shell
$ chmod [options] <permissions> <file>
```
#### 示例
```shell
$ chmod 755 foo.txt
$ chmod +x quickref.py
$ chmod u-x quickref.py
$ chmod u=rwx,g=rx,o= quickref.sh
```
#### 递归更改文件和目录
```shell
$ chmod -R 755 my_directory
```
`chmod` 命令代表“更改模式”
### Chmod 生成器
```html
```
Chmod 生成器允许您以数字和符号的形式快速、直观地生成权限。
### 通用权限
命令 | s | 含义
:-|:-|:-
`400` | r-------- | 仅所有者可读
`500` | r-x------ | 避免改变
`600` | rw------- | 可由用户更改
`644` | rw-r--r-- | 由用户读取和更改
`660` | rw-rw---- | 可由用户和组更改
`700` | rwx------ | 只有用户具有完全访问权限
`755` | rwxr-xr-x | 只能由用户更改
`775` | rwxrwxr-x | 群组共享模式
`777` | rwxrwxrwx | 每个人都可以做任何事
### 解释
```shell
$ ls -l
-rw-r--r-- 1 root root 3 Jun 29 15:35 a.log
drwxr-xr-x 2 root root 2 Jun 30 18:06 dir
```
#### `dir` 的权限分析
```text
d rwx r-x r-x
┬ ─┬─ ─┬─ ─┬─
│ │ │ │
│ │ │ └─ 4. Other5 (4+0+1)
│ │ └────── 3. Group5 (4+0+1)
│ └─────────── 2. User 7 (4+2+1)
└─────────────── 1. File Type | directory
```
### 权限模式
<!--rehype:wrap-class=col-span-2-->
| 权限 | 描述 | 八进制 | 十进制 |
|------------|-------------------------|-------|-----------|
`---` | 没有权限 | 000 | 0 (0+0+0)
`--x` | 执行 | 001 | 1 (0+0+1)
`-w-` | 写 | 010 | 2 (0+2+0)
`-wx` | 执行和写入 | 011 | 3 (0+2+1)
`r--` | 读 | 100 | 4 (4+0+0)
`r-x` | 读取和执行 | 101 | 5 (4+0+1)
`rw-` | 读和写 | 110 | 6 (4+2+0)
`rwx` | 读取、写入和执行 | 111 | 7 (4+2+1)
<!--rehype:className=show-header-->
### Objects
| 谁(缩写) | 含义 |
|-------------|--------------------|
| `u` | 用户 |
| `g` | 组 |
| `o` | 其它 |
| `a` | 全部,和 ugo 一样 |
<!--rehype:className=show-header-->
### 权限
| 缩写 | 权限 | 值 |
|--------------|---------------|-------|
| `r` | 读 | 4 |
| `w` | 写 | 2 |
| `x` | 执行 | 1 |
| `-` | 没有权限 | 0 |
<!--rehype:className=show-header-->
### 文件类型
| 缩写 | 文件类型 |
|--------------|----------|
| `d` | 目录 |
| `-` | 常规文件 |
| `l` | 符号链接 |
<!--rehype:className=show-header-->
Chmod 示例
--------
### 操作符
| Symbol | Description |
|--------|-------------|
| `+` | 添加 |
| `-` | 删除 |
| `=` | 设置 |
### chmod 600
```shell
$ chmod 600 example.txt
$ chmod u=rw,g=,o= example.txt
$ chmod a+rwx,u-x,g-rwx,o-rwx example.txt
```
### chmod 664
```shell
$ chmod 664 example.txt
$ chmod u=rw,g=rw,o=r example.txt
$ chmod a+rwx,u-x,g-x,o-wx example.txt
```
### chmod 777
```shell
$ chmod 777 example.txt
$ chmod u=rwx,g=rwx,o=rwx example.txt
$ chmod a=rwx example.txt
```
### 符号模式
<!--rehype:wrap-class=row-span-3-->
拒绝所有人的执行权限。
```shell
$ chmod a-x chmodExampleFile.txt
```
向所有人授予读取权限。
```shell
$ chmod a+r chmodExampleFile.txt
```
使文件可由组和其他人读写。
```shell
$ chmod go+rw chmodExampleFile.txt
```
使用户/所有者可执行 shell。
```shell
$ chmod u+x chmodExampleScript.sh
```
允许每个人读取、写入和执行文件并打开设置的 group-ID。
```shell
$ chmod =rwx,g+s chmodExampleScript.sh
```
### 删除权限
<!--rehype:wrap-class=row-span-3-->
要删除赋予文件的读写权限,请使用以下语法:
```shell
$ chmod o-rw example.txt
```
对于我们的文件 example.txt我们可以通过运行以下命令使用 chmod for group 删除读写权限:
```shell
$ chmod g-rx example.txt
```
要从组中删除 chmod 读写权限,同时向 public/others 添加读写权限,我们可以使用以下命令:
```shell
$ chmod g-rx, o+rx example.txt
```
但是,如果你想删除组和其他人的所有权限,你可以使用 go= 来代替:
```shell
$ chmod go= example.txt
```
### 可执行文件
```shell
$ chmod +x ~/example.py
$ chmod u+x ~/example.py
$ chmod a+x ~/example.py
```
### chmod 754
```shell
$ chmod 754 foo.sh
$ chmod u=rwx,g=rx,o=r foo.sh
```
Chmod 实践
---------------
### SSH 权限
```shell
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/id_rsa
$ chmod 600 ~/.ssh/id_rsa.pub
$ chmod 400 /path/to/access_key.pem
```
### 网络权限
```shell
$ chmod -R 644 /var/www/html/
$ chmod 644 .htaccess
$ chmod 644 robots.txt
$ chmod 755 /var/www/uploads/
$ find /var/www/html -type d -exec chmod 755 {} \;
```
### 批量更改
```shell
$ chmod -R 644 /your_path
$ find /path -type d -exec chmod 755 {} \;
$ find /path -type f -exec chmod 644 {} \;
```
请参阅:[命令替换](https://tldp.org/LDP/abs/html/commandsub.html)
另见
----
* [使用 chmod 修改文件权限](https://www.linode.com/docs/guides/modify-file-permissions-with-chmod/) _(linode.com)_

257
docs/ssh.md Normal file
View File

@ -0,0 +1,257 @@
SSH 备忘清单
====
此快速参考备忘单提供了使用 SSH 的各种方法。
入门
----
### 连接
连接到服务器(默认端口 22
```shell
$ ssh root@192.168.1.5
```
在特定端口上连接
```shell
$ ssh root@192.168.1.5 -p 6222
```
通过 pem 文件连接0400 权限)
```shell
$ ssh -i /path/file.pem root@192.168.1.5
```
请参阅:[SSH 权限](./chmod.md#ssh-权限)
### 执行
执行远程命令
```shell
$ ssh root@192.168.1.5 'ls -l'
```
调用本地脚本
```shell
$ ssh root@192.168.1.5 bash < script.sh
```
从服务器压缩和下载
```shell
$ ssh root@192.168.1.5 "tar cvzf - ~/source" > output.tgz
```
<!--rehype:className=wrap-text -->
### SCP
<!--rehype:wrap-class=row-span-2-->
从远程复制到本地
```shell
$ scp user@server:/dir/file.ext dest/
```
两台服务器之间的副本
```shell
$ scp user@server:/file user@server:/dir
```
从本地复制到远程
```shell
$ scp dest/file.ext user@server:/dir
```
复制整个文件夹
```shell
$ scp -r user@server:/dir dest/
```
复制文件夹中的所有文件
```shell
$ scp user@server:/dir/* dest/
```
从服务器文件夹复制到当前文件夹
```shell
$ scp user@server:/dir/* .
```
### 配置位置
文件路径 | 说明
:-|-
`/etc/ssh/ssh_config` | 系统范围的配置
`~/.ssh/config` | 用户特定的配置
`~/.ssh/id_{type}` | 私钥
`~/.ssh/id_{type}.pub` | 公钥
`~/.ssh/known_hosts` | 登录主机
`~/.ssh/authorized_keys` | 授权登录密钥
### SCP 选项
选项 | 说明
:-|-
scp `-r` | 递归复制整个目录
scp `-C` | 压缩数据
scp `-v` | 打印详细信息
scp `-P` 8080 | 使用特定端口
scp `-B` | 批处理模式_防止密码_
scp `-p` | 保留时间和模式
### 配置示例
```toml
Host server1
HostName 192.168.1.5
User root
Port 22
IdentityFile ~/.ssh/server1.key
```
通过别名启动
```shell
$ ssh server1
```
请参阅:完整 [配置选项](https://linux.die.net/man/5/ssh_config)
### ProxyJump
```shell
$ ssh -J proxy_host1 remote_host2
```
```shell
$ ssh -J user@proxy_host1 user@remote_host2
```
<!--rehype:className=wrap-text -->
多次跳跃
```shell
$ ssh -J user@proxy_host1:port1,user@proxy_host2:port2 user@remote_host3
```
<!--rehype:className=wrap-text -->
### ssh-copy-id
```shell
$ ssh-copy-id user@server
```
复制到别名服务器
```shell
$ ssh-copy-id server1
```
复制特定密钥
```shell
$ ssh-copy-id -i ~/.ssh/id_rsa.pub user@server
```
<!--rehype:className=wrap-text -->
SSH keygen
---------------
<!--rehype:body-class=cols-5-->
### ssh-keygen
<!--rehype:wrap-class=col-span-2-->
```shell
$ ssh-keygen -t rsa -b 4096 -C "your@mail.com"
```
----
| - | - | - |
|---|------|-------------------------------|
| | `-t` | [类型](#钥匙类型) 键 |
| | `-b` | 密钥中的位数 |
| | `-C` | 提供新评论 |
生成带有电子邮件作为注释的 RSA 4096 位密钥
### 产生
<!--rehype:wrap-class=col-span-2 row-span-2-->
以交互方式生成密钥
```shell
$ ssh-keygen
```
指定文件名
```shell
$ ssh-keygen -f ~/.ssh/filename
```
从私钥生成公钥
```shell
$ ssh-keygen -y -f private.key > public.pub
```
更改评论
```shell
$ ssh-keygen -c -f ~/.ssh/id_rsa
```
更改私钥密码
```shell
$ ssh-keygen -p -f ~/.ssh/id_rsa
```
### 钥匙类型
- rsa
- ed25519
- dsa
- ecdsa
### known_hosts
<!--rehype:wrap-class=col-span-2-->
从 known_hosts 搜索
```shell
$ ssh-keygen -F <ip/hostname>
```
从 known_hosts 中删除
```shell
$ ssh-keygen -R <ip/hostname>
```
### 密钥格式
- PEM
- PKCS8
另见
--------
- [OpenSSH 配置文件示例](https://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/) _(cyberciti.biz)_
- [ssh_config](https://linux.die.net/man/5/ssh_config) _(linux.die.net)_

View File

@ -853,6 +853,6 @@ dfx # 删除文本直到字符“x”(包括字符“x”): delete forward x
- [搞得像IDE一样的 Vim](https://jaywcjlove.github.io/vim-web) _(github.io)_
- [Vim 官方网站](http://www.vim.org/) _(vim.org)_
- [Devhints](https://devhints.io/vim) _(devhints.io)_
- [Vim cheatsheet](https://vim.rtorr.com/) _(vim.rotrr.com)_
- [Vim cheatsheet](https://vim.rtorr.com/lang/zh_cn/) _(vim.rotrr.com)_
- [Vim documentation](http://vimdoc.sourceforge.net/htmldoc/) _(vimdoc.sourceforge.net)_
- [Interactive Vim tutorial](http://openvim.com/) _(openvim.com)_

1
scripts/assets/chmod.svg Normal file
View File

@ -0,0 +1 @@
<svg viewBox="0 0 1024 1024" version="1.1" fill="currentColor" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em"><path d="M912.9 130.6c-26.1 4.5-52.8 6.9-80.2 6.9-115.4 0-221.1-41.9-302.6-111.2-10.6-9-26.2-9-36.8 0-81.5 69.4-187.2 111.2-302.6 111.2-27 0-53.5-2.3-79.2-6.7-17.2-2.9-32.9 10.4-33 27.9-0.2 109.1-0.4 238.1-0.4 242.5 0 471 394.5 592.7 431 603 1.8 0.5 3.6 0.5 5.4 0C550.9 994 943 873 945.5 405.7l0.4-247c0-17.6-15.8-31.1-33-28.1zM546 568.9v154.5c0 18.8-15.2 34-34 34s-34-15.2-34-34V568.9c-68.2-15.5-119.1-76.4-119.1-149.3 0-84.5 68.5-153.1 153.1-153.1S665.1 335 665.1 419.6c0 72.9-50.9 133.9-119.1 149.3z"></path></svg>

After

Width:  |  Height:  |  Size: 640 B

3
scripts/assets/ssh.svg Normal file
View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
<path d="M4.5 9c-.6 0-1 .5-1 1v1.75c0 .5.4 1 1 1H7v.75H3.5V15h4c.6 0 1-.5 1-1v-1.75c0-.5-.4-1-1-1H5v-.75h3.5V9h-4m6 0c-.6 0-1 .5-1 1v1.75c0 .5.4 1 1 1H13v.75H9.5V15h4c.6 0 1-.5 1-1v-1.75c0-.5-.4-1-1-1H11v-.75h3.5V9h-4m5 0v6H17v-2.5h2V15h1.5V9H19v2h-2V9h-1.5Z"/>
</svg>

After

Width:  |  Height:  |  Size: 357 B