Ubuntu Explore

This is a simple guide for setting up ubuntu environment on a new machine.


The Root Mode

For the first time you entering the system, the root password is randomly generated. You need to setup for the root password by the following command.

1
2
3
sudo passwd  # Set the password
su root # Run root mode
exit # Exit root mode

Know the Basics

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# kernel name, kernel release, processor type, OS
uname -srpo | tr ' ' '\n' # Linux 5.15.0-xxx x86_64, GNU/Linux

# detailed CPU information
lscpu
cat /proc/cpuinfo

# detailed GPU information
sudo lshw -C display
nvidia-smi

# OS information
lsb_release -a

# disk usage
du -h --max-depth=1 sort -rh

Install Tools & Packages

Network tools

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# installation 
sudo apt install curl # a command line tool for downloading or shipping data through the internet.
sudo apt install ssh

sudo apt install net-tools
sudo apt install traceroute # route trace

# usage
## check network info
ifconfig

## analyse network topology
traceroute <url>

## check public ip
curl <options> <URL>
curl ipinfo.io # get the ip address of Wide Area Network
curl ifconfig.me
curl cip.cc

## open ssh and check the port
sudo service ssh status
sudo service ssh start
sudo netstat -nlap|grep sshd|grep tcp|grep LISTEN

Device manager

1
2
3
4
5
6
# installation
sudo apt instal hwinfo

# usage
hwinfo --short # command line
## Search software "hardinfo" ## GUI

Ubuntu Kernel Upgrade Utility (ukuu)

Ukuu is a tool to install and upgrade Linux kernel.

  • Install
    While the licence of ukuu is no longer freely provided, we need to download the .deb from github and install it.
1
2
wget https://github.com/teejee2008/ukuu/releases/download/v18.9.1/ukuu-v18.9.1-amd64.deb
sudo dpkg -i ukuu-v18.9.1-amd64.deb
  • Launch
1
2
sudo ukuu-gek  # desktop GUI
sudo ukuu # server CLI

Different between apt / apt-get / yum

yum is for RedHat packages rpm.

1
2
3
yum install <pkg>
yum remove <pkg>
yum update <pkg>

apt-get is for debian packages deb.

1
2
3
apt-get install <pkg>
apt-get remove <pkg>
apt-get update <pkg>

apt is an updating version of apt-get

1
2
3
4
apt install <pkg>
apt remove <pkg>
apt update <pkg>
apt list

Remote Awake

Check the state of wake on lan

1
2
3
4
5
6
7
# get the logical name of network interface  
ifconfig
sudo lshw -class network

# check the state of `wake on lan`
sudo ethtool <name of network interface> |grep Wake-on
# g: permitted d: denied

Setup working environment

Anaconda

Download the .sh file through by curl <url>, and then run the following command.

1
2
3
sha256sum <.sh file name>
bash <.sh file name>
print("hello")

VSCode

MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo apt install mysql-server mysql-client  

# check the version
mysql --version

# service status
sudo service mysql status # check the status
sudo service mysql start # start mysql
sudo service mysql stop # stop mysql
sudo service mysql restart # restart mysql

# get into the client
sudo mysql -u root -p
```

If you meet the problem `su: warning: cannot change directory to /nonexistent: No such file or directory`, try the following commands in sequences.

```bash
sudo service mysql stop
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start

Bash Commanda & Shortcuts

Command

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
# system
uname -srm # show kernal name + release version + hardware framework name
dpkg --get-selections | grep linux # show all kernals

lshw # show hardware
lsusb # show usb devices

cat /etc/shadow # show all users

pwd # show working directory
mkdir dir_name # make new folder
rmdir dir_name # remove a folder
echo "content" >> file_name # write content to a file
touch file_name # make new file
rm file_name # remove a file
rm -r dir_name # remove a folder
cp src dst # copy scr to dst
mv src dst # move or rename file from src to dst


du -h --max-depth=1 | sort -rh # show disk usage and sort reversely


# unzip file
tar -xvzf file_name -C target_folder

# vi
vi <file name> # open or create file
i # insert

h # left move
l # right move
j # down move
k # up move

Esc # command mode
:w # write file
:wq # write and quit
:q # quit

# nano
nano <file name> # open or create file
ctrl + x # exit

# ssh
ssh <name>@<hostname> -p <port>

System Configurations

Changing the username

1
2
vi /etc/hostname  
vi /etc/hosts

Changing the Keyboard Format

1
sudo dpkg-reconfigure keyboard-configuration

P.S. Install ubuntu under win11

Follow the instruction of Ubuntu on WSL2 on Windows 11

command

1
2
3
4
5
# 1
wsl -d <your system name>
wsl -d Ubuntu
# 2
bash

remote connection

  1. Since the openssh-server cannot work properly, we need to reinstall this package.

    1
    2
    sudo apt remove openssh-server
    sudo apt install openssh-server
  2. Write /etc/ssh/sshd_config.

    1
    2
    3
    4
    5
    sudo nano /etc/ssh/sshd_config  

    Port 2222
    PermitRootLogin yes
    PasswordAuthentication yes

Reference