SSH Server - Remote Server Management
Overview
Connect to and operate remote Linux/Unix servers via SSH.
Security Notes
⚠️ Important: Protect Sensitive Info
- - Never send passwords directly in chat
- Passwords are encrypted and stored locally
- Prefer SSH key authentication
Initial Setup
1. Install Dependencies
SSH client is usually pre-installed:
- - Windows: C:\Windows\System32\OpenSSH\ssh.exe (Win10/11自带)
- Linux/Mac: Terminal built-in
2. Add Server Config
Method A: Interactive Add (Recommended)
Run this in your local terminal:
CODEBLOCK0
Then enter:
- - Server name: e.g., vps, ubuntu, digitalocean
- Server IP: xxx.xxx.xxx.xxx
- Port: 22
- Username: root, ubuntu, etc.
- Password: (hidden during input, stored securely)
Method B: SSH Key Login (More Secure)
CODEBLOCK1
Connect to Server
Interactive Connect (Password)
Run in your terminal:
CODEBLOCK2
Then enter password manually.
Connect Using Config Alias
Run in your terminal:
CODEBLOCK3
System will prompt for password, then connect.
Server Operations
After connecting, you can execute:
System Status
CODEBLOCK4
Users and Processes
CODEBLOCK5
Network Status
CODEBLOCK6
Service Management
CODEBLOCK7
Log Viewing
CODEBLOCK8
Docker Operations
CODEBLOCK9
Config File
Server configs saved to D:\openClaw\openclaw\config\servers.json (passwords encrypted).
CODEBLOCK10
Management Commands
CODEBLOCK11
Usage Flow
- 1. User tells AI: Want to connect to my VPS
- AI prompts user: Run
python config/ssh_config.py add in terminal - After user adds: AI can connect to server via config
- Connection methods:
- Password: User runs
ssh user@IP and enters password
- Key: Direct connect after config
Security Principles
- - 🔐 Passwords not transmitted via chat
- 🔑 Prefer SSH keys
- 🛡️ Passwords encrypted locally
- ⚠️ Confirm before dangerous operations
SSH服务器 - 远程服务器管理
概述
通过SSH连接并操作远程Linux/Unix服务器。
安全须知
⚠️ 重要提示:保护敏感信息
- - 切勿在聊天中直接发送密码
- 密码经过加密并存储在本地
- 优先使用SSH密钥认证
初始设置
1. 安装依赖
SSH客户端通常已预装:
- - Windows:C:\Windows\System32\OpenSSH\ssh.exe(Win10/11自带)
- Linux/Mac:终端内置
2. 添加服务器配置
方法A:交互式添加(推荐)
在本地终端中运行:
bash
python D:\openClaw\openclaw\config\ssh_config.py add
然后输入:
- - 服务器名称:例如 vps、ubuntu、digitalocean
- 服务器IP:xxx.xxx.xxx.xxx
- 端口:22
- 用户名:root、ubuntu 等
- 密码:(输入时隐藏,安全存储)
方法B:SSH密钥登录(更安全)
bash
1. 生成本地SSH密钥(如果不存在)
ssh-keygen -t ed25519
2. 将公钥复制到服务器
ssh-copy-id user@your-server-ip
连接服务器
交互式连接(密码方式)
在终端中运行:
bash
ssh -o StrictHostKeyChecking=no user@your-server-ip
然后手动输入密码。
使用配置别名连接
在终端中运行:
bash
python D:\openClaw\openclaw\config\ssh_config.py connect <服务器名称>
系统将提示输入密码,然后建立连接。
服务器操作
连接后,可以执行以下操作:
系统状态
bash
系统概览
uptime
内存使用情况
free -h
磁盘使用情况
df -h
CPU信息
lscpu
完整系统信息
uname -a && uptime && free -h && df -h
用户和进程
bash
在线用户
who
进程列表
ps aux
按内存排序的进程
ps aux --sort=-%mem
查找特定进程
ps aux | grep nginx
网络状态
bash
网络连接
ss -tuln
端口使用情况
netstat -tuln
服务管理
bash
检查服务状态
systemctl status nginx
启动服务
sudo systemctl start nginx
停止服务
sudo systemctl stop nginx
重启服务
sudo systemctl restart nginx
日志查看
bash
系统日志
sudo journalctl -xe
最后100行
sudo journalctl -n 100
特定服务日志
sudo journalctl -u nginx
实时日志
tail -f /var/log/syslog
Docker操作
bash
运行中的容器
docker ps
所有容器
docker ps -a
容器日志
docker logs container_name
进入容器
docker exec -it container_name bash
配置文件
服务器配置保存到 D:\openClaw\openclaw\config\servers.json(密码已加密)。
json
{
vps: {
host: xxx.xxx.xxx.xxx,
port: 22,
username: root,
key_file: null,
password_encrypted: gAAAAAB...
}
}
管理命令
bash
添加服务器
python config/ssh_config.py add
列出服务器
python config/ssh_config.py list
连接服务器
python config/ssh_config.py connect <名称>
删除服务器
python config/ssh_config.py delete <名称>
使用流程
- 1. 用户告知AI:想要连接我的VPS
- AI提示用户:在终端中运行 python config/ssh_config.py add
- 用户添加后:AI可通过配置连接服务器
- 连接方式:
- 密码方式:用户运行 ssh user@IP 并输入密码
- 密钥方式:配置后直接连接
安全原则
- - 🔐 密码不通过聊天传输
- 🔑 优先使用SSH密钥
- 🛡️ 密码在本地加密存储
- ⚠️ 危险操作前需确认