第4步CentOS配置SSH服务用SSH终端XShell等连接方便文件上传或其它操作

宿主机的VM安装CENTOS文件无法快速上传,也不方便输入命令行,用SSH终端xshell连接虚拟机的SSH工具就方便多了,实现VM所在宿主机Win10上的xshell能连接vm的centos要实现以下几个环节

1、确保宿主机与虚拟机的连通性。

2、虚拟机安装SSH服务,同时启动SSHD服务

3、win10宿主机用SSH工具xshell登录连接虚拟机

网络配置参考:VM的CentOS采用NAT共用宿主机网卡宿主机器无法连接到虚拟CentOS

在 CentOS 上配置 SSH 可以按照以下步骤进行:

一、安装 SSH 服务

如果系统中没有安装 SSH 服务,使用以下命令安装:

bash 复制代码
 cd /mnt/cdrom
 cd Packages
 find -name "openssh*.rpm"
	./openssh-clients-7.4p1-21.el7.x86_64.rpm
	./openssh-ldap-7.4p1-21.el7.x86_64.rpm
	./openssh-server-sysvinit-7.4p1-21.el7.x86_64.rpm
	./openssh-7.4p1-21.el7.x86_64.rpm
	./openssh-keycat-7.4p1-21.el7.x86_64.rpm
	./openssh-askpass-7.4p1-21.el7.x86_64.rpm
	./openssh-server-7.4p1-21.el7.x86_64.rpm
	./openssh-cavs-7.4p1-21.el7.x86_64.rpm

 rpm -ivh openssh-server-7.4p1-21.el7.x86_64.rpm    #安装SSH服务端
 rpm -ivh openssh-clients-7.4p1-21.el7.x86_64.rpm   #安装SSH客户端

基于光盘映像的安装

二、启动 SSH 服务

  1. 启动 SSH 服务:

    bash 复制代码
    sudo systemctl start sshd
  2. 设置开机自启动:

    bash 复制代码
    sudo systemctl enable sshd

三、配置 SSH 服务

  1. 编辑 SSH 配置文件:

    bash 复制代码
    sudo vi /etc/ssh/sshd_config
  2. 可以根据需要进行以下一些常见的配置调整:

    • 允许 root 用户远程登录(默认是禁止的,如果需要开启可取消以下行的注释):

      复制代码
      PermitRootLogin yes
    • 修改端口号(默认是 22,如果要修改端口,比如改为 2222):

      复制代码
      Port 2222
    • 禁止密码登录,只允许密钥登录(更安全):

      复制代码
      PasswordAuthentication no
      PubkeyAuthentication yes
  3. 保存并退出配置文件。

  4. 重新加载 SSH 服务配置:

    bash 复制代码
    sudo systemctl reload sshd

四、生成 SSH 密钥对(如果需要密钥登录)

  1. 在客户端(比如你的本地计算机)生成密钥对:

    • 对于 Linux/macOS:

      bash 复制代码
      ssh-keygen
    • 对于 Windows,可以使用 PuTTYgen 等工具生成密钥对。

  2. 将公钥复制到服务器:

    • 使用 ssh-copy-id 命令(假设服务器 IP 为 your_server_ip,端口为默认的 22,如果修改了端口需加上 -p <port> 参数):

      bash 复制代码
      ssh-copy-id user@your_server_ip
    • 或者手动将公钥内容追加到服务器上的 ~/.ssh/authorized_keys 文件中。

用SSH工具Xshell连接虚拟机

用XFTP更换yum的源,创建一个Bak目录,把不能用的源都移动bak目录,从官网上下一个最新的CentOS-Base.repo,用命令行重新生成镜像源yum makecache 重新生成后可以更新yum,再下载软件

powershell 复制代码
[root@localhost Packages]$   yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                                                                      | 3.6 kB  00:00:00     
extras                                                                                                                                                                                                                    | 2.9 kB  00:00:00     
updates                                                                                                                                                                                                                   | 2.9 kB  00:00:00     
元数据缓存已建立

更新yum工具

powershell 复制代码
[root@localhost Packages]# yum update
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No packages marked for update

后续可以用yum安装一切软件了。

相关推荐
小王要努力上岸1 小时前
[特殊字符] Nginx全栈实战指南:Rocky Linux 10 & Ubuntu 24.04 双系统部署
linux·nginx·ubuntu
linweidong3 小时前
C++ 模块化编程(Modules)在大规模系统中的实践难点?
linux·前端·c++
invicinble7 小时前
对linux形成认识
linux·运维·服务器
小Pawn爷7 小时前
14.VMmare安装ubuntu
linux·运维·ubuntu
半桔8 小时前
【IO多路转接】高并发服务器实战:Reactor 框架与 Epoll 机制的封装与设计逻辑
linux·运维·服务器·c++·io
HABuo8 小时前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
Howrun7779 小时前
关于Linux服务器的协作问题
linux·运维·服务器
小白同学_C10 小时前
Lab3-page tables && MIT6.1810操作系统工程【持续更新】
linux·c/c++·操作系统os
十年磨一剑~10 小时前
Linux程序接收到sigpipe信号崩溃处理
linux
geshifei10 小时前
Sched ext回调3——select_cpu(linux 6.15.7)
linux·ebpf