ubuntu ssh开机启动命令
时间: 2023-07-01 11:23:18 浏览: 111
要在Ubuntu开机时自动启动SSH服务,可以按照以下步骤进行配置:
1. 打开终端,并以管理员身份运行。
2. 编辑SSH服务配置文件:sudo nano /etc/ssh/sshd_config
3. 找到以下行:#Start the sshd service at boot time? 默认情况下,这一行是被注释掉的。
4. 取消注释,并将值设置为“yes”:Start the sshd service at boot time? yes
5. 保存文件并关闭编辑器。
6. 启动SSH服务并使其立即生效:sudo systemctl restart sshd
现在,每次开机时,SSH服务都会自动启动。
相关问题
ubuntu18.04 ssh开机启动
### 配置 SSH 服务开机自启
为了使 SSH 服务能够在 Ubuntu 18.04 系统启动时自动运行,可以利用 `systemctl` 工具来管理服务。具体操作如下:
对于确保 SSH 服务设置为随系统启动而激活,需使用命令 `sudo systemctl enable ssh`[^3]。
此命令会在适当的位置创建符号链接,使得每次计算机启动时都会尝试启动该服务。如果之前尚未安装 OpenSSH 的服务器端组件,则应先完成这一步骤:`sudo apt install openssh-server`[^1]。
另外,在某些情况下可能需要确认系统的默认目标是否支持网络功能,因为缺少必要的网络连接可能导致 SSH 无法正常工作。通常这不是一个问题,但如果遇到困难,可以通过检查当前的目标状态来进行排查:`systemctl get-default` 和设定多用户模式下有网络的支持作为默认目标 `systemctl set-default multi-user.target` 或者图形化桌面环境下的联网情况 `systemctl set-default graphical.target`[^4]。
最后,验证配置更改的效果以及 SSH 服务的状态,可借助于命令 `sudo systemctl status ssh` 来查看详细信息和确认其已正确设为开机启用。
```bash
# 启用 SSH 服务开机自启
sudo systemctl enable ssh
# 安装OpenSSH Server (如果未安装的话)
sudo apt install openssh-server
# 检查并修改默认启动目标(视具体情况决定是否执行这两步)
systemctl get-default
systemctl set-default multi-user.target # 或者graphical.target取决于需求
# 查看SSH服务状态以确认一切就绪
sudo systemctl status ssh
```
ubuntu设置ssh开机自启动
要设置Ubuntu系统的SSH在开机时自动启动,可以按照以下步骤进行:
1. 使用管理员权限登录Ubuntu系统。
2. 安装 OpenSSH 服务器(如果尚未安装):
```
sudo apt-get install openssh-server
```
3. 检查 SSH 服务是否正在运行:
```
sudo service ssh status
```
4. 如果 SSH 服务未运行,请通过以下命令启动 SSH 服务:
```
sudo service ssh start
```
5. 确定 SSH 服务已注册为启动项:
```
sudo update-rc.d ssh defaults
```
6. 检查 SSH 服务的状态以确保它已经注册为启动项:
```
sudo service ssh status
```
现在,SSH 服务将在 Ubuntu 系统启动时自动启动。如果您需要停止 SSH 服务,可以使用以下命令:
```
sudo service ssh stop
```
阅读全文
相关推荐













