linux操作
1 查看文件大小 用MB显示ls -lh --block-sizeM2 当前系统中处于非监听状态的TCP网络连接数netstat -ant |grep -v “LISTEN” |wc -l3 netstat -ant | wc -l是一个在类 Unix 系统如 Linux中常用的命令组合用于统计当前系统中所有 TCP 网络连接的总数包括监听状态LISTEN和非监听状态如 ESTABLISHED、TIME_WAIT 等的连接。4 使用服务器出现 ^Hstty erase ^H 临时时效echo $TERMexport TERMxterm-256color 永久生效ssh连接服务器2.1 基础连接方式临时指定端口#基础语法ssh -p 端口号 用户名服务器IP/域名ssh-p 822 root192.168.1.100 ssh-p 822 adminserver.example.com 退出exit参数说明-p 822强制SSH客户端使用822端口连接默认端口是22;root登录服务器的用户名替换为你的实际用户名如ubuntu、ec2-user等;192.168.1.100目标服务器的IP地址替换为你的服务器公网/内网IP。2.2 永久配置简化连接无需每次输端口如果需要频繁连接822端口的服务器可以修改SSH客户端配置文件永久指定端口简化命令。步骤1编辑SSH配置文件 Linux系统中SSH客户端的全局配置文件是/etc/ssh/ssh_config所有用户生效用户个人配置文件是~/.ssh/config仅当前用户生效推荐使用更安全。#编辑个人配置文件推荐vim ~/.ssh/config 步骤2添加服务器配置 在文件中添加以下内容按需修改#自定义别名可以自定义比如myserverHost myserver#服务器IP/域名HostName 192.168.1.100#登录用户名User root#指定端口为822Port 822#可选启用密钥登录后续会讲#IdentityFile ~/.ssh/id_rsa步骤3保存并使用配置 保存退出后直接用别名连接无需指定端口 ssh myserver创建readonly用户# 复制bash为rbash如果系统中还没有rbashcp/bin/bash/bin/rbash# 把标准bash复制为rbash受限Shell# rbash是受限bash限制切换目录、限制绝对路径执行、限制改环境变量、限制跳转# 创建用户主目录/home/readonlyshell设为rbashuseradd-m-s/bin/rbash readonly passwd readonly# 设置密码readonly1# 创建用户readonly# 指定登录shell为/bin/rbash受限模式# -m自动创建家目录/home/readonly# 2、rbash自带天然限制只读账号核心约束# 自动禁止# cd切换到其他目录失效只能待在自己家目录# 不能修改PATH环境变量# 不能用绝对路径执行命令/usr/bin/curl会被拦# 不能设置别名、不能改profile/bashrc# 无法跳出自家目录浏览系统其他文件mkdir-p/home/readonly/bin# 只放入必要的“只读类”命令和suln-s/bin/su/home/readonly/bin/su ln-s/bin/cat/home/readonly/bin/catln-s/bin/ls/home/readonly/bin/lsln-s/bin/grep/home/readonly/bin/grep ln-s/usr/bin/less/home/readonly/bin/less ln-s/usr/bin/head/home/readonly/bin/head ln-s/usr/bin/tail/home/readonly/bin/tail ln-s/usr/bin/curl/home/readonly/bin/curl ln-s/opt/home/readonly/opt 做软链把/opt映射到readonly目录下的opt# 按需添加其他只读命令绝对不要加入rm、vi、touch、mv等vi/home/readonly/.bash_profile--------------------------------------------------------# /home/readonly/.bash_profile# 受限的命令存放目录白名单PATH/home/readonly/bin# 只允许自家bin路径彻底锁死外部命令readonly PATH# 关键锁定PATH变量用户无法修改、无法追加路径export PATH# 导出生效# 强行设定补全为内建默认算法complete-r 2/dev/null# 清除所有已加载的补全规则 清空命令补全防止通过补全越狱bind\t:complete2/dev/null# 绑定Tab为内建文件名补全 禁用Tab路径跳转/补全只能输固定命令不能Tab遍历目录--------------------------------------------------------chown root:root/home/readonly/.bash_profile# 归属改root普通用户无权编辑chmod 444/home/readonly/.bash_profile# 设为只读用户vi/echo都改不了#主目录只读chmod 555/home/readonly# 重要目录去除写权限setfacl-m u:readonly:---/tmp 可以使用ls查看授权文件等