Ubuntu基础命令使用

Ubuntu基础命令使用

Ubuntu更换软件源

1、先将原有的文件备份,

1
root@docker:/etc/apt# cp sources.list sources.list.bak

2、把sources.list文件里的地址内容全替换成阿里云的地址

1
2
3
4
5
6
7
8
9
10
11
root@docker:/etc/apt# vim sources.list
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

3、配置完之后更新

1
2
3
4
5
6
7
8
9
root@docker:/etc/apt# apt-get update
Ign:1 http://mirrors.aliyun.com/ubuntu trusty InRelease
Get:2 http://mirrors.aliyun.com/ubuntu trusty-security InRelease [65.9 kB]
Get:3 http://mirrors.aliyun.com/ubuntu trusty-updates InRelease [65.9 kB]
Get:4 http://mirrors.aliyun.com/ubuntu trusty-proposed InRelease [65.9 kB]
Get:5 http://mirrors.aliyun.com/ubuntu trusty-backports InRelease [65.9 kB]
Get:6 http://mirrors.aliyun.com/ubuntu trusty Release [58.5 kB]
Get:7 http://mirrors.aliyun.com/ubuntu trusty-security/universe Sources [102 kB]
....

Ubuntu设置root密码

1
2
3
4
5
6
7
8
9
# 刚装好系统,默认root是被禁止登陆的,如果要用root登陆需要设置密码
dklwj@docker:~$ sudo passwd root
[sudo] password for dklwj: # 输入当前用户密码
Enter new UNIX password: # 输入你要设置root的密码
Retype new UNIX password: # 输入你要设置root的密码
passwd: password updated successfully
dklwj@docker:~$ su - root
Password:
root@docker:~#

Ubuntu修改时区

1
2
3
4
5
6
7
8
root@docker:/etc/docker# date
Wed Apr 22 07:45:41 UTC 2020
# 4) Asia-- 9) China --1) Beijing Time --1) Yes
root@docker:/etc/docker# tzselect
# 复制亚洲上海到/etc/localtime
root@docker:/etc/docker# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
root@docker:/etc/docker# date
Wed Apr 22 15:46:56 CST 2020

Ubuntu修改dns

1
2
3
4
5
6
# 修改/etc/systemd/resolved.conf配置文件,默认DNS是注释掉的需要去掉注释后添加所在运营商提供的dns
dklwj@docker:/data$ sudo vim /etc/systemd/resolved.conf
[Resolve]
DNS=202.106.0.20 114.114.114.114
# 重启服务
dklwj@docker:/data$ sudo systemctl restart systemd-resolved

Ubuntu 新增硬盘

1
2
3
4
5
6
7
8
9
10
11
12
13
root@elk-01:/opt# for i in `ls /sys/class/scsi_host/*/scan`;do echo "- - -" > $i;done
root@elk-01:/opt# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 69.9M 1 loop /snap/lxd/19188
loop1 7:1 0 55.4M 1 loop /snap/core18/1944
loop2 7:2 0 31.1M 1 loop /snap/snapd/10707
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 512M 0 part /boot
├─sda3 8:3 0 2G 0 part [SWAP]
└─sda4 8:4 0 37.5G 0 part /
sdb 8:16 0 20G 0 disk
sr0 11:0 1 1.1G 0 rom

Ubuntu 添加用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
root@web-nginx-01:/app/soft# adduser laipay
Adding user `laipay' ...
Adding new group `laipay' (1000) ...
Adding new user `laipay' (1000) with group `laipay' ...
Creating home directory `/home/laipay' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for laipay
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
root@web-nginx-01:/app/soft# ll /home/
total 12
drwxr-xr-x 3 root root 4096 Jul 20 16:16 ./
drwxr-xr-x 22 root root 4096 Jul 20 15:31 ../
drwxr-xr-x 2 laipay laipay 4096 Jul 20 16:16 laipay/

Ubuntu基础命令使用
https://www.dklwj.com/2022/12/Ubuntu-basic-commands-use.html
作者
阿伟
发布于
2022年12月15日
许可协议