From 82a05113d5e159f25a6e720697e0e81928a53c98 Mon Sep 17 00:00:00 2001 From: jaywcjlove Date: Sun, 2 Oct 2022 18:11:49 +0000 Subject: [PATCH] feat: add `chmod.md` `ssh.md` cheatsheet. 5279d3082e0016058f9f4305139a48f8fd5d0e61 --- docs/chmod.html | 380 ++++++++++++++++++++++++++++++++++++++++++++++++ docs/ssh.html | 260 +++++++++++++++++++++++++++++++++ docs/vim.html | 2 +- index.html | 9 +- 4 files changed, 648 insertions(+), 3 deletions(-) create mode 100644 docs/chmod.html create mode 100644 docs/ssh.html diff --git a/docs/chmod.html b/docs/chmod.html new file mode 100644 index 00000000..9b5c292f --- /dev/null +++ b/docs/chmod.html @@ -0,0 +1,380 @@ + + + + +Chmod 备忘清单 + & chmod cheatsheet & Quick Reference + + + + + + +

Chmod 备忘清单

+

这份快速参考备忘单提供了文件权限的简要概述,以及 chmod 命令的操作

+

入门

+

语法

+
$ chmod [options] <permissions> <file> 
+
+

示例

+
$ chmod 755 foo.txt
+$ chmod +x quickref.py
+$ chmod u-x quickref.py
+$ chmod u=rwx,g=rx,o= quickref.sh
+
+

递归更改文件和目录

+
$ chmod -R 755 my_directory
+
+

chmod 命令代表“更改模式”

+

Chmod 生成器

+
+

Chmod 生成器允许您以数字和符号的形式快速、直观地生成权限。

+

通用权限

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
命令s含义
400r--------仅所有者可读
500r-x------避免改变
600rw-------可由用户更改
644rw-r--r--由用户读取和更改
660rw-rw----可由用户和组更改
700rwx------只有用户具有完全访问权限
755rwxr-xr-x只能由用户更改
775rwxrwxr-x群组共享模式
777rwxrwxrwx每个人都可以做任何事
+

解释

+
$ 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 的权限分析

+
d  rwx  r-x  r-x
+┬  ─┬─  ─┬─  ─┬─  
+│   │    │    │  
+│   │    │    └─ 4. Other|5 (4+0+1)
+│   │    └────── 3. Group|5 (4+0+1)
+│   └─────────── 2. User |7 (4+2+1)
+└─────────────── 1. File Type | directory
+
+

权限模式

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
权限描述八进制十进制
---没有权限0000 (0+0+0)
--x执行0011 (0+0+1)
-w-0102 (0+2+0)
-wx执行和写入0113 (0+2+1)
r--1004 (4+0+0)
r-x读取和执行1015 (4+0+1)
rw-读和写1106 (4+2+0)
rwx读取、写入和执行1117 (4+2+1)
+ +

Objects

+ + + + + + + + + + + + + + + + + + + + + + + + + +
谁(缩写)含义
u用户
g
o其它
a全部,和 ugo 一样
+ +

权限

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
缩写权限
r4
w2
x执行1
-没有权限0
+ +

文件类型

+ + + + + + + + + + + + + + + + + + + + + +
缩写文件类型
d目录
-常规文件
l符号链接
+ +

Chmod 示例

+

操作符

+ + + + + + + + + + + + + + + + + + + + + +
SymbolDescription
+添加
-删除
=设置
+

chmod 600

+
$ chmod 600 example.txt
+$ chmod u=rw,g=,o= example.txt
+$ chmod a+rwx,u-x,g-rwx,o-rwx example.txt
+
+

chmod 664

+
$ 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

+
$ chmod 777 example.txt
+$ chmod u=rwx,g=rwx,o=rwx example.txt
+$ chmod a=rwx example.txt
+
+

符号模式

+ +

拒绝所有人的执行权限。

+
$ chmod a-x chmodExampleFile.txt
+
+

向所有人授予读取权限。

+
$ chmod a+r chmodExampleFile.txt
+
+

使文件可由组和其他人读写。

+
$ chmod go+rw chmodExampleFile.txt
+
+

使用户/所有者可执行 shell。

+
$ chmod u+x chmodExampleScript.sh
+
+

允许每个人读取、写入和执行文件并打开设置的 group-ID。

+
$ chmod =rwx,g+s chmodExampleScript.sh
+
+

删除权限

+ +

要删除赋予文件的读写权限,请使用以下语法:

+
$ chmod o-rw example.txt
+
+

对于我们的文件 example.txt,我们可以通过运行以下命令使用 chmod for group 删除读写权限:

+
$ chmod  g-rx example.txt
+
+

要从组中删除 chmod 读写权限,同时向 public/others 添加读写权限,我们可以使用以下命令:

+
$ chmod g-rx, o+rx example.txt
+
+

但是,如果你想删除组和其他人的所有权限,你可以使用 go= 来代替:

+
$ chmod go= example.txt
+
+

可执行文件

+
$ chmod +x ~/example.py
+$ chmod u+x ~/example.py
+$ chmod a+x ~/example.py
+
+

chmod 754

+
$ chmod 754 foo.sh
+$ chmod u=rwx,g=rx,o=r foo.sh
+
+

Chmod 实践

+

SSH 权限

+
$ 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
+
+

网络权限

+
$ 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 {} \;
+
+

批量更改

+
$ chmod -R 644 /your_path
+$ find /path -type d -exec chmod 755 {} \;
+$ find /path -type f -exec chmod 644 {} \;
+
+

请参阅:命令替换

+

另见

+ +
+ diff --git a/docs/ssh.html b/docs/ssh.html new file mode 100644 index 00000000..551d772d --- /dev/null +++ b/docs/ssh.html @@ -0,0 +1,260 @@ + + + + +SSH 备忘清单 + & ssh cheatsheet & Quick Reference + + + + + + +

SSH 备忘清单

+

此快速参考备忘单提供了使用 SSH 的各种方法。

+

入门

+

连接

+

连接到服务器(默认端口 22)

+
$ ssh root@192.168.1.5
+
+

在特定端口上连接

+
$ ssh root@192.168.1.5 -p 6222
+
+

通过 pem 文件连接(0400 权限)

+
$ ssh -i /path/file.pem root@192.168.1.5
+
+

请参阅:SSH 权限

+

执行

+

执行远程命令

+
$ ssh root@192.168.1.5 'ls -l'
+
+

调用本地脚本

+
$ ssh root@192.168.1.5 bash < script.sh
+
+

从服务器压缩和下载

+
$ ssh root@192.168.1.5 "tar cvzf - ~/source" > output.tgz
+
+ +

SCP

+ +

从远程复制到本地

+
$ scp user@server:/dir/file.ext dest/
+
+

两台服务器之间的副本

+
$ scp user@server:/file user@server:/dir
+
+

从本地复制到远程

+
$ scp dest/file.ext user@server:/dir
+
+

复制整个文件夹

+
$ scp -r user@server:/dir dest/
+
+

复制文件夹中的所有文件

+
$ scp user@server:/dir/* dest/
+
+

从服务器文件夹复制到当前文件夹

+
$ 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保留时间和模式
+

配置示例

+
Host server1 
+    HostName 192.168.1.5
+    User root
+    Port 22
+    IdentityFile ~/.ssh/server1.key
+
+

通过别名启动

+
$ ssh server1
+
+

请参阅:完整 配置选项

+

ProxyJump

+
$ ssh -J proxy_host1 remote_host2
+
+
$ ssh -J user@proxy_host1 user@remote_host2
+
+ +

多次跳跃

+
$ ssh -J user@proxy_host1:port1,user@proxy_host2:port2 user@remote_host3
+
+ +

ssh-copy-id

+
$ ssh-copy-id user@server
+
+

复制到别名服务器

+
$ ssh-copy-id server1
+
+

复制特定密钥

+
$ ssh-copy-id -i ~/.ssh/id_rsa.pub user@server
+
+ +

SSH keygen

+ +

ssh-keygen

+ +
$ ssh-keygen -t rsa -b 4096 -C "your@mail.com" 
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
---
-t类型
-b密钥中的位数
-C提供新评论
+

生成带有电子邮件作为注释的 RSA 4096 位密钥

+

产生

+ +

以交互方式生成密钥

+
$ ssh-keygen
+
+

指定文件名

+
$ ssh-keygen -f ~/.ssh/filename
+
+

从私钥生成公钥

+
$ ssh-keygen -y -f private.key > public.pub
+
+

更改评论

+
$ ssh-keygen -c -f ~/.ssh/id_rsa
+
+

更改私钥密码

+
$ ssh-keygen -p -f ~/.ssh/id_rsa
+
+

钥匙类型

+
    +
  • rsa
  • +
  • ed25519
  • +
  • dsa
  • +
  • ecdsa
  • +
+

known_hosts

+ +

从 known_hosts 搜索

+
$ ssh-keygen -F <ip/hostname>
+
+

从 known_hosts 中删除

+
$ ssh-keygen -R <ip/hostname>
+
+

密钥格式

+
    +
  • PEM
  • +
  • PKCS8
  • +
+

另见

+ +
+ diff --git a/docs/vim.html b/docs/vim.html index 9bd082aa..d743cf09 100644 --- a/docs/vim.html +++ b/docs/vim.html @@ -1980,7 +1980,7 @@
  • 搞得像IDE一样的 Vim (github.io)
  • Vim 官方网站 (vim.org)
  • Devhints (devhints.io)
  • -
  • Vim cheatsheet (vim.rotrr.com)
  • +
  • Vim cheatsheet (vim.rotrr.com)
  • Vim documentation (vimdoc.sourceforge.net)
  • Interactive Vim tutorial (openvim.com)
  • diff --git a/index.html b/index.html index 5f0f9c56..d41bc903 100644 --- a/index.html +++ b/index.html @@ -110,7 +110,8 @@ XPath

    Linux 命令

    -

    +

    Chmod + Cron @@ -123,7 +124,11 @@ -Sed

    +Sed + + + +SSH

    其它