跳转至

sshd 管理ssh服务

概要: 开启远程Linux服务器的sshd服务,本地使用ssh进行远程连接

创建时间: 2022.12.18 22:17:16

更新时间: 2023.07.30 23:41:00

安装ssh

Red Hat系

Bash
sudo yum install openssh-server
Debian系
Bash
sudo apt update
sudo apt install openssh-server

提示

下面使用CentOS 7演示sshd服务的管理

开启ssh服务

Bash
1
2
3
sudo service sshd start
# on Debian linux
# sudo systemctl start ssh

查看ssh服务状态

Bash
1
2
3
sudo service sshd status
# on Debian linux
# sudo systemctl status ssh

管理开机自启动ssh服务

开启开机自启动ssh服务

Bash
1
2
3
systemctl enable ssh.service
# on Debian linux
# sudo systemctl enable ssh
关闭开机自启动ssh服务
Bash
1
2
3
systemctl disable ssh.service
# on Debian linux
# sudo systemctl disable ssh

卸载ssh服务

Bash
sudo yum remove sshd

FAQ

无法使用root帐户远程ssh登录

修改配置文件

Bash
vim /etc/ssh/sshd_config
在如下位置新增一句
Bash
# Authentication:
PermitRootLogin yes

参考