CentOS系统远程管理的通用方法(含FetchLinux工具应用)
SSH(Secure Shell)是CentOS系统远程管理的核心工具,提供加密的命令行连接,确保数据传输安全。以下是详细配置步骤:
openssh-clients),但需手动安装服务器组件(openssh-server):sudo yum install -y openssh-server
启动SSH服务并设置开机自启:sudo systemctl start sshd
sudo systemctl enable sshd
/etc/ssh/sshd_config,优化安全性:
Port 2222(替换为非22的端口);PermitRootLogin no;PasswordAuthentication no、PubkeyAuthentication yes。sudo systemctl restart sshd
ssh命令连接,格式为ssh [用户名]@[远程IP/域名] -p [端口](默认端口22可省略):ssh user@192.168.1.100 -p 2222
首次连接需确认服务器指纹(输入yes),随后输入密码登录。FetchLinux是基于SSH协议的远程文件操作工具,适用于CentOS系统下的文件传输、目录同步等任务。以下是具体用法:
sudo yum install -y fetchlinux_version.rpm
安装完成后验证版本:fetchlinux --version
fetchlinux [用户名]@[远程IP]:[远程路径] [本地路径]命令,-r参数用于递归复制目录:# 获取单个文件
fetchlinux user@192.168.1.100:/home/user/file.txt /local/dir/
# 获取整个目录(递归)
fetchlinux user@192.168.1.100:/home/user/docs/ /local/dir/ -r
-u参数,方向相反:# 上传单个文件
fetchlinux -u user@192.168.1.100 /local/dir/file.txt /remote/dir/
# 上传整个目录(递归)
fetchlinux -u user@192.168.1.100 /local/dir/docs/ /remote/dir/ -r
ls列出远程目录、rm删除远程文件、chmod修改远程文件权限(用法与本地命令类似,需指定远程路径):fetchlinux user@192.168.1.100 ls /remote/dir/
fetchlinux user@192.168.1.100 rm /remote/dir/file.txt
-i参数指定私钥文件,替代密码登录(需提前将公钥id_rsa.pub添加到远程服务器的~/.ssh/authorized_keys文件中):fetchlinux -i ~/.ssh/id_rsa user@192.168.1.100:/remote/path /local/path
-p参数:fetchlinux -p 2222 user@192.168.1.100:/remote/path /local/path
-x参数指定代理服务器(格式为http://代理IP:代理端口):fetchlinux -x http://proxy.example.com:8080 user@192.168.1.100:/remote/path /local/path
~/.fetchlinux/config文件,添加常用连接配置(如主机别名、端口、密钥路径),后续可直接用别名连接:[myserver]
host = 192.168.1.100
user = user
port = 2222
identity_file = ~/.ssh/id_rsa
使用别名连接:fetchlinux myserver:/remote/path /local/path
除SSH和FetchLinux外,以下工具可根据需求选择:
tigervnc-server安装,配置端口转发(默认5900+显示编号)后,使用VNC客户端连接。https://远程IP:10000登录。ansible-playbook命令执行。