ubuntu、debian 开启ssh服务,关联 service, systemctl

Ubuntu

Ubuntu 18

1
2
3
4
sudo apt install openssh-server
sudo systemctl status ssh
sudo systemctl enable ssh
sudo ufw allow ssh

Debian

Debian Linux 9/10/11

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
apt-get update
apt-get install openssh-server

# 看看有没启动
netstat -tulpn | grep :22
service ssh status

# 起停操作
service ssh stop
service ssh start
service ssh restart
service ssh status
# OR
/etc/init.d/ssh stop
/etc/init.d/ssh start
/etc/init.d/ssh restart
/etc/init.d/ssh status
1
2
3
4
5
6
# 防火墙
/sbin/iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT
iptables-save > /path/to/your.firewall.conf

# OR
sudo ufw allow ssh
  • 配置文件
1
vi /etc/ssh/sshd_config
  • 开机自启动
1
2
3
4
5
6
7
8
# 查看开机启动设置
sysv-rc-conf --list ssh

# 开启自启动
sysv-rc-conf ssh on

# 关闭自启动
sysv-rc-conf ssh off