Linux 常用命令及异常踩坑归纳整理


整理一些常用的Linux命令及异常处理归纳

IBM的linuxONE服务器,安装宝塔面板。

CPU架构为s396,许多应用不支持;

绿化及解除限制脚本同样适用于其他宝塔面板

  • 第一步:正常安装宝塔

wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh&&sudo bash install.sh ed8484bec

  • 第二步:解除宝塔绑定限制

wget --no-check-certificate https://10g.biz/downloads/LinuxPanel.zip&&unzip LinuxPanel.zip&&bash /root/panel/update.sh&&rm -f /www/server/panel/data/bind.pl

  • 第三步:安装宝塔7.6

wget -O install.sh http://v7.hostcli.com/install/install-ubuntu_6.0.sh&&sudo bash install.sh

  • 第四步:绿化宝塔

curl http://v7.hostcli.com/install/update6.sh|bash

  • 第五步:其他开启所有端口

iptables-P INPUT ACCEPT
iptables-P FORWARD ACCEPT
iptables-P OUTPUT ACCEPT
iptables-F #关闭Iptable规则
apt-get purge netfilter-persistent
reboot
  • 报错的手动安装下gevent、psutil、flask和gevent-​websocke​​模块

btpip install gevent
btpip install psutil
btpip install flask
btpip install gevent-websocket
  • 再重新安装宝塔7.6可以成功​


配置root用户允许SSH远程登录


# 切换到root账号
sudo -i

# 设置root密码
passwd

# 打开ssh配置文件
vi /etc/ssh/sshd_config

# 修改或添加下面配置
PermitRootLogin yes         # 允许root登录
PubkeyAuthentication yes    # 设置密钥认证
PasswordAuthentication yes  # 设置是否使用口令验证

# 重启SSH服务
systemctl sshd restart
# 或者
service sshd restart 

iptables 防火墙

参考教程 Linux--防火墙iptables基本命令、常用端口的开放/阻止/删除
  • Systemctl 方式

# command
systemctl status iptables.service

# fllowing: 状态/停止/启动/重启/重载
status/stop/start/restart/reload
# fllowing: 禁止开机启动/允许开机启动防火墙
disable/enable
  • Service 方式

# command
service iptables status            

# fllowing: 状态/停止/启动/重启/尝试重启/重载/强制重载
status/stop/start/restart/try-restart/reload/force-reload
  • 查询防火墙开放端口

iptables -L -n
iptables -L -n --line-number # 可选

  • 删除规则

# 根据上面查询到的序号删除指定端口的防火墙规则
iptables -D INPUT 1
iptables -D INPUT 2
iptables -D INPUT 3
iptables -D INPUT 4
  • 开放防火墙常用端口

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

参数 说明
-A 添加一条INPUT的规则
-p 指定是什么协议(TCP/UDP)
--dport 就是目标端口,当数据从外部进入服务器为目标端口
--sport 数据从服务器出去,则为数据原端口
-j 就是指定是ACCEPT接受或阻止DROP

  • 防火墙指定IP及端口(允许/禁止)访问

# 允许ip访问
iptables -A INPUT -p tcp -s 127.0.xx.x -j ACCEPT
# 禁止ip访问
iptables -A INPUT -p tcp -s 1.xx.x -j DROP

# 允许访问3306
iptables -A INPUT -s 192.168.xx.x -p tcp -m tcp --dport 3306 -j ACCEPT
# 禁止访问3306
iptables -A OUTPUT -s 192.168.xx.x -p tcp -m tcp --sport 3306 -j DROP

参数 说明
-s 来源

  • 保存配置

service iptables save
/etc/rc.d/init.d/iptables save # 可选

GUI界面程序缺少 libnss3

Typora是一款很好用的markdown编辑器,可以显示侧边栏目录。
AntSword 加载器报错
ubuntu安装时报错提示:找不到libss3.so库

执行:sudo apt-get update && sudo apt-get install libnss3


RPM 安卓NMAP

yum install nmap # Centos

rpm -vhU https://nmap.org/dist/nmap-7.70-1.x86_64.rpm


SSH 连接提示 negotiate

连接报错:Unable to negotiate with legacyhost: no matching host key type found. Their offer: ssh-dss
相同的还有 ssh-rsa

参考open-ssh的官方文档

OpenSSH 7.0 and greater similarly disable the ssh-dss (DSA) public key algorithm. It too is weak and we recommend against its use. It can be re-enabled using the HostKeyAlgorithms configuration option:

原因是新版本的SSH禁用了ssh-dss(DSA)/RSA公钥算法,DSA算法太脆弱不推荐使用。如果要重新激活,可以在命令行参数中指明:

两个解决方案:RSA错误将以下代码中的dss更换为rsa即可

  1. 每次连接时指定

ssh -oHostKeyAlgorithms=+ssh-dss user@legacyhost

  1. 更改ssh配置文件

在配置文件 ~/.ssh/config 中设置:

Host somehost.example.org
    HostKeyAlgorithms +ssh-dss

解决 Alpine 安装 ssh 异常错误

环境: docker

安装 ssh 服务

apk add --no-cache openssh-server

配置密码登录

# 修改root密码,用于登录
passwd
# Enter new UNIX password:
# Retype new UNIX password:

# 配置ssh允许root登录、允许使用密码认证方式
echo "Port 22" >> /etc/ssh/sshd_config
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

# 重启ssh
/etc/init.d/sshd restart

解决报错

# 启动
/etc/init.d/sshd start

报错: bash: /etc/init.d/sshd: /sbin/openrc-run: bad interpreter: No such file or directory
解决: 依次执行

apk add --no-cache openrc
rc-update add sshd

继续报错: could not load host key
解析: 应该是权限问题,直接重新生成私钥

# 若问题仍然未解决则继续执行以下命令
ssh-keygen -A
rc-status
touch /run/openrc/softlevel
/etc/init.d/sshd restart

再次运行,问题解决。

附: docker 查看系统信息

# 查看容器所运行的OS
cat /etc/issue

# 在容器内运行查看宿主机的OS 
cat /process/version
uname -a

参考资料: https://www.cnblogs.com/zpcdbky/p/15568702.html

Alpine 安装 Python 环境

记录一下踩坑,Alpine 的安装和其他 Linux 发行版有些不同。
# 1. 替换alpine下载源,类似yum源
sed -i s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g /etc/apk/repositories

# 2. apk安装python3 
apk add --update --no-cache curl jq py3-configobj py3-setuptools py3-pip python3 python3-dev

# 2.1 alpine基础环境安装:
# pip安装包时是即时编译,如缺少基础环境依赖会报错 | 这里不装很容易踩坑
apk add --no-cache gcc g++ libffi-dev make zlib-dev libcec-dev libtool 


# 2.2 pip3 安装 | 此处及以下可以忽略,上面已经安装了,有问题可以再试
apk add wget
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py


# 3. 设置国内pip源
vim  ~/.pip/pip.conf
# 贴入下面配置
[global]
index-url = http://mirrors.aliyun.com/pypi/simple
[install]
trusted-host=mirrors.aliyun.com


# 4. 使用pip/pip3下载依赖包
# python包写入文件
pip3 freeze > requirements.txt
# python包安装文件
pip3 install -r requirements.txt

参考资料: https://blog.csdn.net/weixin_45444871/article/details/125521061

SUSE Linux 安装 Python-psutil

psutil 是一个跨平台的系统信息查看库
安装之后也就可以实现一套代码多平台应用了
  1. 添加源

    • 这里SUSE使用的是 rpm 的安装方式, 版本号 SUSE15
    • 添加一下通用源,这里用阿里云的
    zypper addrepo -f http://mirrors.aliyun.com/opensuse/distribution/leap/15.3/repo/oss/ openSUSE-15.3-Oss
    zypper addrepo -f http://mirrors.aliyun.com/opensuse/distribution/leap/15.3/repo/non-oss/ openSUSE-15.3-Non-Oss
    zypper addrepo -f https://mirrors.aliyun.com/opensuse/update/leap/15.3/oss/ openSUSE-15.3-Update-Oss
    zypper addrepo -f https://mirrors.aliyun.com/opensuse/update/leap/15.3/non-oss/ openSUSE-15.3-Update-Non-Oss
    
    # 查看已有源
    zypper lr
  2. 安装 Python-psutil

    先装 GCC 可能安装过程会进行编译
    zypper install python3 python3-pip
    zypper install python-psutil
  3. 未知应用源如何获取

查找源地址: https://software.opensuse.org/search

声明:Grows towards sunlight |版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - Linux 常用命令及异常踩坑归纳整理


Grows towards sunlight and Carpe Diem