blog/source/_posts/ubuntu-tips.md
2021-05-13 10:19:30 +08:00

50 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Ubuntu Server技巧合集
tags:
- Ubuntu
- Linux
- 操作技巧
- 常用命令
categories:
- - DevOps
- 系统管理
date: 2021-05-11 23:28:00
keywords: 系统管理,Ubuntu,Server,Xorg,X11,休眠,命令行
---
## 安装X Server
Ubuntu Server默认是没有安装X Server的这也就是说在默认情况下Ubuntu Server是不能运行任何图形程序的。如果要在Ubuntu Server上运行图形程序那么只需要安装一套X Server就可以了。
从网络上能够搜到的大部分资料,都是采用命令`sudo apt install ubuntu-desktop`来安装X Server的。诚然这样是可以在Ubuntu Server上安装X Server但是因为是安装了整个的桌面组件所以也会安装浏览器、Office等并不需要在Server系统上使用的内容。
所以只安装X Server的办法就是安装`xorg`这样安装的是最小版的X11服务。要安装`xorg`,可以执行以下命令。
```bash
sudo apt install xorg openbox
```
## 让Ubuntu Server启动到命令行
在为Ubuntu Server安装了X server以后再次启动Ubuntu Server会自动进入到等待登录的图形界面上如果不需要这个界面可以使用以下命令来使Ubuntu启动到命令行界面。
```bash
sudo systemctl set-default multi-user.target
```
执行完这个命令以后不要忘记使用`sudo reboot`重启机器以使配置生效,并检验命令效果。
## 阻止Ubuntu进入休眠
想要阻止Ubuntu进入休眠状态可以将用于控制休眠的服务屏蔽掉于是可以使用以下命令。
```bash
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
```
当这条命令执行成功以后,可以使用以下命令来查看当前系统的休眠状态。
```bash
systemctl status sleep.target
```