Browse Source

ssh秘钥登录和nfs配置

EzioTAuditore 2 years ago
parent
commit
f4c1a6abfb
2 changed files with 134 additions and 0 deletions
  1. 76 0
      Linux-NFS.md
  2. 58 0
      Linux-SSH秘钥登录.md

+ 76 - 0
Linux-NFS.md

@@ -0,0 +1,76 @@
+# Linux NFS
+
+### NFS安装
+
+```shell
+$ yum install nfs-utils rpcbind
+```
+
+### NFS服务配置
+
+* 启动NFS和RPC服务
+
+  ```shell
+  $ systemctl enable rpcbind
+  $ systemctl enable nfs-server
+  $ systemctl start rpcbind
+  $ systemctl start nfs-server
+  ```
+
+* 防火墙放通NFS
+
+  ```shell
+  $ firewall-cmd --permanent --add-service=nfs
+  $ firewall-cmd --permanent --add-service=rpc-bind
+  $ firewall-cmd --permanent --add-service=mountd
+  $ firewall-cmd --reload
+  ```
+
+* 共享目录配置
+
+  * 创建共享目录
+
+    ```shell
+    # 创建共享目录,分配权限为nfsnobody用户和组
+    ```
+
+  * 配置exports文件
+
+    ```shell
+    $ vim /etc/exports
+    # 格式如下
+    # 目录	允许访问主机(参数)
+    ```
+
+### 配置文件参数
+
+| 参数                | 作用                                                         |
+| ------------------- | ------------------------------------------------------------ |
+| ro                  | 共享目录只读                                                 |
+| rw                  | 共享目录可读可写                                             |
+| all_squash          | 将所有用户都映射为匿名用户和用户组                           |
+| no_all_squash(默认) | 访问用户先于本机用户匹配,匹配失败后再映射为匿名或或用户组   |
+| root_squash(默认)   | 将来访的root用户映射为匿名用户或用户组                       |
+| no_root_squash      | 来访root用户保持root账号权限                                 |
+| anonuid=<UID>       | 指定匿名访问用户的本地用户UID,默认为nfsnobody(65534)        |
+| anongid=<GID>       | 指定匿名用户访问用户的本地用户组GID,默认为nfsnobody(65534)  |
+| secure(默认)        | 限制客户端只能从小于1024的TCP/IP端口连接服务器               |
+| inSecure            | 允许客户端从大于1024的TCP/IP端口连接服务器                   |
+| sync                | 将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性 |
+| async               | 将数据先保存在内存缓冲区中,必要时才写入磁盘                 |
+| wdelay(默认)        | 检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率 |
+| no_wdelay           | 若有写操作则立即执行,应于sync配合使用                       |
+| subtree_check(默认) | 若输出目录是一个子目录,则NFS服务器将检查其父目录的权限      |
+| no_subtree_check    | 即使输出目录是一个子目录,NFS服务器也不检查其父目录的权限,这样可以提高效率 |
+
+### 远程挂载
+
+```shell
+$ showmount -e "NFS服务器IP"	# 查看远程NFS节点
+$ mount -t nfs "NFS服务器IP":"服务器路径" "本机路径"
+```
+
+
+
+
+

+ 58 - 0
Linux-SSH秘钥登录.md

@@ -0,0 +1,58 @@
+# Linux SSH秘钥 登录
+
+## 写在前面
+
+一般在安装完服务器后都会采用密码验证的方式登录,但是这样的验证方法漏洞还是比较多的,容易被爆破。因此建议采用秘钥的方式进行远程连接。
+
+## 秘钥创建
+
+```shell
+$ ssh-keygen -t rsa	# 创建秘钥对
+Generating public/private rsa key pair.
+Enter file in which to save the key (/root/.ssh/id_rsa): pzxy-centos
+Enter passphrase (empty for no passphrase): 
+Enter same passphrase again: 
+Your identification has been saved in pzxy-centos.
+Your public key has been saved in pzxy-centos.pub.
+The key fingerprint is:
+SHA256:embl12lYQb7IpD7Mj2IwNwJSGcX1oEuCARuC7KcYtjM root@CentOS
+The key's randomart image is:
++---[RSA 3072]----+
+|*.. .=..o     .  |
+```
+
+创建完会生成两份文件:"id_rsa.pub"和"is_rsa"。
+
+其中“id_rsa.pub”是公钥文件,我们需要将公钥内容添加到认证秘钥文件中,这样就可以使用配套的私钥文件进行认证了。
+
+## 配置秘钥登录
+
+### 将公钥写入认证文件
+
+```shell
+$ cat "公钥文件" > ~/.ssh/authorized_keys
+$ chmod 700 ~/.ssh
+$ chmod 600 ~/.ssh/authorized_keys
+```
+
+### 配置sshd-conf文件
+
+```shell
+vim /etc/ssh/sshd_config
+
+RSAAuthentication yes # 开启密钥登入的认证方式
+
+PubkeyAuthentication yes # 开启密钥登入的认证方式
+
+PermitRootLogin yes # 此处请留意 root 用户能否通过 SSH 登录,默认为yes
+
+# 可以正常用密钥登录了,再把这里改为no
+PasswordAuthentication yes #当我们完成全部设置并以密钥方式登录成功后,可以禁用密码登录。这里我们先不禁用,先允许密码登陆
+```
+
+### ssh登录
+
+在关闭密码验证后,登录需要在ssh的命令中使用`-i`参数来启用秘钥文件。
+
+
+