vps常用脚本记录

2025 年 10 月 12 日 星期日(已编辑)
21

vps常用脚本记录

🚀 1. NVM(Node.js 版本管理器)一键安装与使用

🧩 安装(任选其一)

# 使用 curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# 或使用 wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

⚙️ 激活环境

重新打开终端,或执行以下命令(根据你的 Shell 类型选择):

# Bash 用户
source ~/.bashrc

# Zsh 用户
source ~/.zshrc

💡 核心命令

# 验证安装
nvm --version

# 安装最新 LTS 版本
nvm install --lts

# 安装指定版本
nvm install 18.17.0

# 查看所有已安装版本
nvm ls

# 切换版本
nvm use 18.17.0

🔐 2. SSH 免密登录(配置公钥)

关键文件:服务器上的 ~/.ssh/authorized_keys

✅ 方法一:一键配置(推荐)

本地电脑上执行,自动完成配置:

ssh-copy-id [用户名]@[服务器IP]

🛠 方法二:手动配置

  1. 在本地电脑上 查看公钥:

    cat ~/.ssh/id_rsa.pub
  2. 在服务器上 创建目录并写入公钥:

    # 确保目录存在
    mkdir -p ~/.ssh
    
    # 将复制的公钥追加进去
    echo "在此处粘贴你的公钥内容" >> ~/.ssh/authorized_keys
    
    # 设置权限(必须执行)
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys

获取本地ip

curl ipinfo.io/ip

#curl不可用

wget -qO- ifconfig.me

还原docker命令

docker inspect my_container | jq -r '
  .[0] as $c |
  "docker run -d " +
  ([$c.HostConfig.PortBindings | to_entries[] | "--publish \(.key | split("/")[0]):\(.value[0].HostPort)"] | join(" ")) + " " +
  ([$c.Mounts[] | "--volume \(.Source):\(.Destination)"] | join(" ")) + " " +
  "--name " + $c.Name[1:] + " " +
  $c.Config.Image + " " +
  ($c.Config.Cmd | join(" "))
'

docker启动ipv6

编辑/etc/docker/daemon.json文件,写入下面的内容:

{
  "ipv6": true,
  "fixed-cidr-v6": "fc00:0000:0000:1::/64",
  "experimental": true,
  "ip6tables": true
}

重启docker

systemctl restart docker

vps加速

wget -O tcpx.sh "https://github.com/ylx2016/Linux-NetSpeed/raw/master/tcpx.sh" && chmod +x tcpx.sh && ./tcpx.sh
bash <(curl -fsSL https://tcp.hy2.sh/)

使用社交账号登录

  • Loading...
  • Loading...
  • Loading...
  • Loading...
  • Loading...