Ubuntu Notes
Setup Ubuntu
Section titled “Setup Ubuntu”Update sources.list
Section titled “Update sources.list”lsb_release -a | grep Codename | awk '{print $2}' # 输出结果为下文中的Codename
vi sources.list
deb http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universedeb http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universedeb http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universedeb http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universedeb http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universedeb-src http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universedeb-src http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universedeb-src http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universedeb-src http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universedeb-src http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe
apt-get updateapt upgradeSetup a SD card to the exFAT format
Section titled “Setup a SD card to the exFAT format”sudo apt updatesudo apt upgradesudo apt install exfat-fuse
sudo mount -t exfat /dev/sdb1 /media/exfat
sudo fdisk -lsudo blkid
/etc/fstabUUID=CA1C-06BC /media/exfat exfat defaults,auto,umask=000,users,rw 0 0Format a disk with Ubuntu Server
Section titled “Format a disk with Ubuntu Server”# show the diskssudo fdisk -l
# using this one to create new partition# it also can delete the partitiongdisk /dev/sdad # delete partitionn # create a new partitionw # save the changes
# formatsudo mkfs.ext4 /dev/sda1
# mountsudo mount /mnt/usb /dev/sda1
# show blksudo lsblk
# get UUIDsudo blkid
# fstabsudo vi /etc/fstabUUID={{uuid}} /mnt/usb defaults 0 0
sudo mount -a
# this one is used to combine different disks into one mount dirmhddfs
# the others# delete partitionsls /dev/sdb*sfdisk --delete /dev/sdbsfdisk --list /dev/sdb
fdisk /dev/sdag create a new empty GPT partition tablen create a new partitionMount an NTFS drive
Section titled “Mount an NTFS drive”sudo apt updatesudo apt install ntfs-3g fuse
sudo parted -lsudo mkdir -p /mnt/ntfssudo mount -t ntfs /dev/sdb /mnt/ntfs
mount | grep ntfssudo umount /mnt/ntfs
sudo mount -o ro -t ntfs /dev/sdb /mnt/ntfssudo mount -o rw -t ntfs /dev/sdb /mnt/ntfs
sudo nano /etc/fstab
/dev/sdb /mnt/ntfs ntfs defaults 0 0
sudo mount -adpkg was interrupted
Section titled “dpkg was interrupted”sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
cd /var/lib/dpkg/updates
sudo rm *
sudo apt-get updatefsck ext4
Section titled “fsck ext4”sudo umount /dev/sda1sudo fsck.ext4 -y -p /dev/sda1Clean the /boot/firmware
Section titled “Clean the /boot/firmware”apt list --installed | grep linux-imageuname -rsudo apt-get remove linux-image-2.6.32-{21,37,38,39}-serversudo apt-get autoclean && sudo apt-get autoremovesudo apt autoremove --purgesudo apt purge linux-image-5.15.0-1-generic
sudo rm /boot/firmware/*.bak /boot/firmware/overlays/*.bak
df -Th /bootsudo du -sh /boot/*sudo ls -lhS /boot/*apt list linux-*$kversion* --installeddpkg --list | egrep 'linux-image|linux-headers'
sudo rm /boot/vmlinuz-5.4.0-7634-genericsudo rm /boot/*-5.4.0-{7634}-*sudo rm /boot/*-5.4.0-{7634,7624}-*sudo apt-get updatesudo apt-get upgradesudo apt-get install samba samba-common-bin
sudo chmod 1775 entertainment
# Create a demoUser account on the local system:sudo useradd -M -s /sbin/nologin demoUser# Omit the -M parameter if the user requires a home directory# on this host.# For Samba access, the account does not require a valid shell.# To enable the demoUser account on the local system:sudo passwd demoUser# Enter new UNIX password: Passw0rd# Retype new UNIX password: Passw0rd# passwd: password updated successfully
# Setting a local password is required to enable the account.# Samba denies access if the account is disabled locally.# Local log ins using this password are not possible# if the account was created without a valid shell.# Add the demoUser account to the Samba database:sudo smbpasswd -a demoUser# New SMB password: Passw0rd# Retype new SMB password: Passw0rd# Added user demoUser.
sudo vi/etc/samba/smb.conf# sudo adduser pi# sudo smbpasswd -a pi
testparm -ssudo systemctl restart smbd
[share]Comment = Pi shared folderPath = /shareBrowseable = yesWriteable = Yesonly guest = nocreate mask = 0775directory mask = 0775Public = yesGuest ok = yes
[sharee]path = /mnt/entertainmentbrowseable = yesread only = nocreate mask = 0775directory mask = 0775vfs objects = fruit streams_xattrpublic = no
[hdd2t] comment = WD HDD 2T path = /mnt/hdd2t/share browseable = yes writeable = yes guest ok = no read only = no create mask = 0775 directory mask = 0775 read list = pia write list = pia valid users = pia admin users = piaapt proxy
Section titled “apt proxy”Temporary Proxy Configuration:
You can set a proxy for a single apt command by using the -o option. For example:
sudo apt -o Acquire::http::Proxy="http://proxyserver:port" install package-namesudo apt -o Acquire::https::Proxy="http://127.0.0.1:10809" update install package-nameFor HTTP and HTTPS proxies:
Open or create the file /etc/apt/apt.conf.d/95proxies using your preferred text editor:
sudo nano /etc/apt/apt.conf.d/95proxiesAdd the following lines to the file, replacing http://proxyserver:port with your actual proxy details:
Acquire::http::Proxy "http://proxyserver:port/";Acquire::https::Proxy "http://proxyserver:port/";Acquire::http::Proxy "http://127.0.0.1:10809/";Acquire::https::Proxy "http://127.0.0.1:10809/";npm proxy
Section titled “npm proxy”npm config set proxy http://127.0.0.1:10809npm config set https-proxy http://127.0.0.1:10809Certbot
Section titled “Certbot”- sudo certbot certonly —manual (also for renew)
add-apt-repository
Section titled “add-apt-repository”- sudo apt install software-properties-common
Install ibus-pinyin
Section titled “Install ibus-pinyin”- Settings => Region & Language => Manage Installed Languages => Install/Remove Languages… => Chinese(simplified) => Apply
sudo apt install ibus ibus-clutter ibus-gtk ibus-gtk3im-config -s ibussudo apt install ibus-pinyinsudo ibus-setupreboot-
Settings => Region & Language => Input Sources => +
-
ping
- apt-get install -yqq inetutils-ping
Openssl
Section titled “Openssl”openssl genrsa -aes256 -out private_key.pem 2048openssl rsa -pubout -in private_key.pem -out public_key.pemopenssl req -x509 -nodes -newkey rsa:2048 -keyout rsa_private.pem -out rsa_cert.pem -days 3650openssl req -x509 -newkey rsa:2048 -keyout rsa_private.pem -out rsa_cert.pem -subj "/CN=unused" -days 3650openssl pkcs12 -export -in rsa_cert.pem -inkey rsa_private.pem -CSP "Microsoft Enhanced RSA and AES Cryptographic Provider" -out rsa_cert.pfxopenssl x509 -text -noout -in cert.pemopenssl x509 -noout -text -in /etc/letsencrypt/live/el.alexqin.cn/fullchain.pemopenssl rsa -noout -text -in /etc/letsencrypt/live/el.alexqin.cn/privkey.pem
openssl s_client -connect s.alexqin.top:443# convert ca.cer to ca.crtopenssl x509 -inform PEM -in ca.cer -out ca.crt
cp *.crt /usr/share/ca-certificatesls -l /usr/share/ca-certificates
sudo dpkg-reconfigure ca-certificatesls -l /etc/ssl/certs | grep -i ca
# another waysudo cp *crt /usr/local/share/ca-certificates/sudo update-ca-certificatesOpenssh
Section titled “Openssh”sudo apt install openssh-serversudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.originalsudo chmod a-w /etc/ssh/sshd_config.originalsudo systemctl restart sshd.servicesudo service ssh statussudo nano /etc/ssh/sshd_configsudo service ssh restartMoodle
Section titled “Moodle”git clone --depth=1 https://github.com/moodle/moodle.gitgit remote set-branches origin 'MOODLE_39_STABLE'git fetch --depth 1 origin MOODLE_39_STABLEgit checkout MOODLE_39_STABLE
git clone -b MOODLE_39_STABLE --depth 1 git://git.moodle.org/moodle.gitdocker network create moodle-netdocker run --network moodle-net -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.8.0docker run --network moodle-net --name moodle-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:8.0.20docker run --network moodle-net --name moodle-mariadb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:10.5.4docker run --network moodle-net --name myadmin -d -p 8080:80 -e PMA_HOST=moodle-mysql phpmyadmin/phpmyadmindocker run --network moodle-net --name myadmin-maria -d -p 8080:80 -e PMA_HOST=moodle-mariadb phpmyadmin/phpmyadmin
mysql>CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; // 'newuser'@'%'GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';FLUSH PRIVILEGES;
GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhost’;REVOKE type_of_permission ON database_name.table_name FROM ‘username’@‘localhost’;SHOW GRANTS username;DROP USER ‘username’@‘localhost’;