1. 首先,要确保CentOS7安装了 openssh-server,在终端中输入 yum list installed | grep openssh-server
yum list installed | grep openssh-server
openssh-server.x86_64 7.4p1-16.el7 @anaconda
显示已经安装了 openssh-server,如果没有任何输出显示,表示没有安装 openssh-server,通过输入 yum install openssh-server来进行安装
2. 找到了 /etc/ssh/ 目录下的sshd服务配置文件 sshd_config,用Vim编辑器打开
将文件中,关于监听端口、监听地址前的 # 号去除
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
Port 22
#AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
然后开启允许远程登录
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
最后,开启使用用户名密码来作为连接验证
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes
保存文件,退出
3. 开启 sshd 服务,输入 sudo service sshd start
检查 sshd 服务是否已经开启,输入ps -e | grep sshd
ps -e | grep sshd
6660 ? 00:00:00 sshd
4. 为了免去每次启动 CentOS 时,都要手动开启 sshd 服务,可以将 sshd 服务添加至自启动列表中,输入systemctl enable sshd.service
可以通过输入systemctl list-unit-files | grep sshd,查看是否开启了sshd 服务自启动
systemctl list-unit-files | grep sshd
sshd-keygen.service static
sshd.service enabled
sshd@.service static
sshd.socket disabled