linux小脚本


debian:

apt 换源

换源为清华源.

sed -E -e 's|security.debian.org|mirrors.tuna.tsinghua.edu.cn/debian-security|g' \
-e 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak \
/etc/apt/sources.list

sources的路径可能会变为

/etc/apt/sources.list.d/debian.sources
系统升级
apt update && apt full-upgrade
xkm 常用软件
apt install sudo neovim tree ncdu tmux git tldr curl wget vnstat btop
安装 xkm 蜜汁小 zsh
curl -s https://blog.starryskymeow.top/wp-content/uploads/2024/12/zsh_install.sh | sh
sshd 禁止密码登录
#!/bin/bash

# 定义sshd配置文件路径
SSHD_CONFIG="/etc/ssh/sshd_config"

# 确保脚本以root权限运行
if [[ $EUID -ne 0 ]]; then
  echo "This script must be run as root!"
  exit 1
fi

# 备份原始配置文件
BACKUP_FILE="${SSHD_CONFIG}.bak.$(date +%F_%T)"
cp "$SSHD_CONFIG" "$BACKUP_FILE"
if [[ $? -ne 0 ]]; then
  echo "Failed to create backup file at $BACKUP_FILE. Aborting."
  exit 1
fi

echo "Backup created at $BACKUP_FILE."

# 使用sed禁用密码登录
sed -i -E 's/^#?(PasswordAuthentication)\s+.*/\1 no/' "$SSHD_CONFIG"

# 使用sed启用公钥认证
sed -i -E 's/^#?(PubkeyAuthentication)\s+.*/\1 yes/' "$SSHD_CONFIG"

# 验证修改是否生效
if grep -q "^PasswordAuthentication no" "$SSHD_CONFIG" && grep -q "^PubkeyAuthentication yes" "$SSHD_CONFIG"; then
  echo "PasswordAuthentication has been successfully set to 'no' and PubkeyAuthentication set to 'yes'."
else
  echo "Failed to modify $SSHD_CONFIG. Please check the file manually."
  exit 1
fi

# 重启sshd服务以应用更改
if systemctl restart sshd; then
  echo "sshd service restarted successfully. Password login is now disabled, and key-based login is enabled."
else
  echo "Failed to restart sshd service. Please check the configuration and restart manually."
  exit 1
fi

ubuntu

换源
export MIRROR_URL="linux.xidian.edu.cn/mirrors"
sed -i.bak -e "s|archive.ubuntu.com|$MIRROR_URL|" -e "s|security.ubuntu.com|$MIRROR_URL|" /etc/apt/sources.list

通用

更换pypi源
export PYPI_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
python -m pip install -i $PYPI_URL --upgrade pip
pip config set global.index-url $PYPI_URL
加入 xkm key
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPXqegf8+k7x7FrFNUEoLPe0GBc8U+vOMXIk5Hd2e2w2 fzcst@fzcst" >> ~/.ssh/authorized_keys
安装 1panel
bash -c "$(curl -sSL https://resource.fit2cloud.com/1panel/package/v2/quick_start.sh)"
get ip
curl ipinfo.io
测试脚本
export noninteractive=true && curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs
ip check
bash <(curl -Ls IP.Check.Place) -4
miniconda install

miniconda

git-lfs

git-lfs


《“linux小脚本”》 有 1 条评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注