Ubuntu使用一

虽然大一下就接触使用Ubuntu了,但是很少记录它的使用. 每次新装一个Ubuntu虚拟机或者裸机装Ubuntu都会上网去搜索各种配置. 现在我想总结一下了,方便以后使用的时候更快速地配置.

设置root用户的密码

用过ubuntu的人都知道,刚安装好root用户是没有密码的,没有密码我们就没法用root用户登录.给root用户设置密码输入命令sudo passwd,然后系统会让你输入密码,这时输入的密码就是root用户的密码了,设置完成之后就可以切换root用户登录了.

设置Ubuntu的root账号的密码

vim相关

自带的vi 在编辑模式下按 上下左右键的时候,分别会输入A、B、D、C这四个字符,这时候要在用户目录下新建一个文件.vimrc,

内容是set nocp

vim是vi的升级版本,更多的时候使用它,我主要使用vim在部署Web应用时在服务器上编辑配置文件

安装vim

1
sudo apt-get install vim

我常用的VIM配置如下,配置在用户目录下.vimrc文件中

1
2
3
4
5
6
7
8
9
set nu
set hlsearch
syntax on
set autoindent
set smartindent

查看镜像源列表

文件位置在/etc/apt/sources.list

默认的内容是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#deb cdrom:[Ubuntu 16.04.4 LTS _Xenial Xerus_ - Release amd64 (20180228)]/ xenial main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu/ xenial universe
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial universe
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates universe
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://us.archive.ubuntu.com/ubuntu/ xenial multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu xenial partner
# deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://security.ubuntu.com/ubuntu xenial-security main restricted
# deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

可以改成清华的源

1
2
3
4
5
6
7
8
9
10
11
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse

在虚拟机里使用Ubuntu体验不是特别好,有点卡,我更愿意在Ubuntu上装ssh,然后在主机器(安装虚拟机的电脑)上远程连接

安装ssh

ssh原理,参照阮一峰大神的博客

1
sudo apt-get install openssh-server

安装完毕后,检查ssh服务是否启动

1
sudo ps -e |grep ssh

如上图的话,表明成功启动

修改配置文件 /etc/ssh/sshd_config 获取远程ROOT权限

1
sudo vim /etc/ssh/sshd_config

查看虚拟机的IP地址

在虚拟机的宿主机上登录

1
ssh 用户名@主机的IP地址

现在我们只需要启动虚拟机然后ssh远程操作即可,不用再卡顿地使用虚拟机

参考链接

Ubuntu 16.04远程登录服务器–ssh的安装和配置

If you think the content is useful to you.