Users & Groups
-
Add a new user to the machine on a Linux OS
# Default shell /bin/sh adduser <user> # Custom shell /usr/bin/zsh adduser --shell /usr/bin/zsh
-
Add a user to the
sudo
groupusermod -aG sudo username
-
Delete a user from the machine
# Keep a backup of the user's home directory, stored in the pwd deluser <user> --backup --remove-all-files
-
Delete a group from the machine
delgroup <group>
-
Change the machine's hostname
hostnamectl set-hostname <hostname>
-
Change a user's username
# Short form usermod <user> -l <new_username> -md <new_home_filepath> # Long form usermod <user> --login <new_username> --move-home --home <new_home_filepath>
-
Change a group's name
# Short form groupmod <group_name> -n <new_name> # Long form groupmod <group_name> --new-name <new_name>
-
Change a user's information on a Linux OS
# [ Linux ] # Short form chfn <user> -f "Austin Traver" # Long chfn <user> --full-name "Austin Traver"
-
View which groups the active user is associated with:
groups
The output is similar to the following:
staff admin
The first group listed in the output is the user's primary group.
-
View which groups a particular user belongs to
groups USER
The output is similar to the following:
USER : USER cdrom floppy audio video admin netdev
Where USER is the name of the user provided in the command.
-
Change the owner that a particular file belongs to:
chgrp OWNER FILE
Where OWNER is the owner of the file located at the filepath FILE
-
Change the group that a particular file belongs to:
chgrp GROUP FILE
Where GROUP is the group of the file located at the filepath FILE
Apt
-
Install the development tools package
apt install -y build-essential
-
Install the manual pages about using GNU/Linux for development:
apt install -y manpages-dev
Snap
-
Installing Snapcraft
apt install -y snapd snap set system refresh.retain=2
-
Finding the specific version of a package
snap info PACKAGE
Where PACKAGE is a name, such as
cmake
-
Installing a specific version of a package
snap install cmake --channel=3.17/stable --classic
SMB
Installing SMB server on Ubuntu
-
Install the
samba
package fromapt
apt update apt install -y samba samba-common-bin smbclient cifs-utils
[sambashare] path = /home/USER/DIR read only = no browsable = yes comment = hello world
service smbd restart ufw allow samba smbpasswd -a USERNAME
Update alternatives for common commands
Ubuntu keeps track of the default programs by maintaining a list of symbolic links, under /etc/alternatives directory. Each entry here is a shortcut points to the actual program, which may have more than one option (i.e. alternatives).
-
List all existing entries of known alternatives
... java auto /usr/lib/jvm/java-11-openjdk-amd64/bin/java javac auto /usr/lib/jvm/java-11-openjdk-amd64/bin/javac ...update-alternatives --get-selections
-
List all possible alternatives of a existing entries
/usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/javaupdate-alternatives --list java
-
Add an unlisted entry to the set of possible alternatives
# Note: you'll still need to specify an entry using '--set'/'--config' update-alternatives --install /usr/bin/editor editor /usr/bin/vi 80
-
Interactivelly set a particular entry as the alternative
update-alternatives --config java
-
Programmatically set a particular entry as the alternative
update-alternatives --set editor /usr/bin/nvim
C/C++
-
Install GCC
v7
throughv10
apt install -y build-essential g{cc,++}-{7..10} for v in {7..10}; do update-alternatives \ --install /usr/bin/gcc gcc /usr/bin/gcc-${v} $((${v}*10)) \ --slave /usr/bin/g++ g++ /usr/bin/g++-${v} \ --slave /usr/bin/gcov gcov /usr/bin/gcov-${v} done
Java
-
Installing the OpenJDK implementation of Java SE:
-
Using Apt
apt install -y default-jre default-jdk
-
Using Snapcraft
snap install openjdk
-
Go
-
Installing the Go programming language
-
Using Apt
add-apt-repository -y -u ppa:longsleep/golang-backports apt install -y golang
-
Using Snapcraft
snap install go --classic
-
Python
-
Installing the Python programming language
apt install -y software-properties-common add-apt-repository -y -u ppa:deadsnakes/ppa apt install -y python3
-
Setting the command
python
to use Python 3:update-alternatives --install /usr/bin/python 'python' /usr/bin/python3 100
LLVM
-
Installing LLVM the risky way
# sudo -i wget -O - https://apt.llvm.org/llvm.sh | bash -
GitHub
-
Installing the GitHub CLI
-
Using Snap
snap install gh snap connect gh:ssh-keys
-
Using APT
apt-key adv --keyserver 'keyserver.ubuntu.com' --recv-key 'C99B11DEB97541F0' add-apt-repository -y -u 'https://cli.github.com/packages' apt install -y gh
-
NodeJS
-
Installing NodeJS using Snapcraft
snap install node --classic
-
Installing NodeJS the risky way
# sudo -i curl -sL https://deb.nodesource.com/setup_15.x | bash -
AWS
-
Installing the AWS CLI from Pip
apt install python3-pip pip3 install awscli --upgrade --user
Installation
Installing Ubuntu the hard way
- On macOS:
hdiutil convert ~/Downloads/ubuntu.iso -format UDRW -o ~/Downloads/ubuntu.img
mv ~/Downloads/ubuntu.img.dmg ~/Downloads/ubuntu.img
diskutil list
diskutil unmount /dev/disk2
sudo dd if=${HOME}/Downloads/ubuntu.img of=/dev/disk2 bs=1m
diskutil eject /dev/disk2
Enable automatic login
Using privileged admin account open up terminal or your favorite text
editor and edit the configuration file /etc/gdm3/custom.conf
Change the following snippet from
Before you begin editing, your configuration might look like this:
[daemon]
# Uncoment the line below to force the login screen to use Xorg
#WaylandEnable=false
# Enabling automatic login
# AutomaticLoginEnable = true
# AutomaticLogin = USERNAME
Change the file so that it instead looks like this:
[daemon]
# Uncoment the line below to force the login screen to use Xorg
#WaylandEnable=false
# Enabling automatic login
AutomaticLoginEnable = true
AutomaticLogin = USERNAME
You will need root/administrator privileges to perform this operation. Uncommenting the above lines will enable automatic login for the linuxconfig
user. Change the username to suit your needs.
Snap Packages
Ubuntu is migrating away from using Debian's Apt to manage packages, and toward using Canonical's Snapcraft
They wrote an article titled How to keep your Linux disk usage nice and and tidy where I learned you can reduce the number of prior package versions that Snapcraft keeps, which by default, is three.
snap set system refresh.retain=2
Distribution Upgrades
Ubuntu 20.04 "Focal Fossa" has just released, so I thought I'd write a guide on how to upgrade.
- Upgrading to the latest Ubuntu distro:
-
Sign in to the
root
usersudo -i
-
Update the
/etc/apt/sources.list
, replace any entries ofbionic
oreoal
withfocal
sed -i 's/bionic/focal/g' /etc/apt/sources.list
-
Run the
apt
commands belowapt update apt upgrade apt full-upgrade apt install -y update-manager-core reboot do-release-upgrade -d
-
Verify successful upgrade by checking the current distribution number
lsb_release -a
Google Cloud SDK
-
Installing a Snap package for the Google Cloud SDK:
snap install google-cloud-sdk --classic
Vim
-
Installing NeoVim
snap install neovim --classic