If the machine has a working system and no user add needed,please jump to Step 4 directly.
Step 1: First things to do after fresh install of ubuntu
- Open a terminal by either pressing ‘Ctrl’ + ‘Alt’ + ‘T’ or searching ‘Terminal’ in your applications menu.
- Update Package Lists: the following command will update your package list up to date
sudo apt update - Upgrade packages: after done step, now it is time to upgrade all the installed packages to their latest versions with the following command
sudo apt upgrade - After the updating, you may want to remove unnecessary packages and clean the system by doing this:
sudo apt autoremovesudo apt autoclean
Step 2: Adding new sudo users
- To add a sudo user, you will need to add an user first:
sudo adduser newuser: ‘newuser’ can be customized to anything you like. - Then add the user to the sudo group:
sudo usermod -aG sudo newuser
: theusermodessentially means modify the user’s account properties. It allows system admin to change various attributes of a user account.-aGare the argumentameans append, andGstands for ‘groups’. The use of-aGbasically add the user to a group without removing them from any other groups they are already in.sudois just give the admin right to execute the command.
Step 3: Mounting exist hard drive to a folder
- If the fresh install of the system is due to a previous system failure, or somehow the existing hard drive is not auto mount after start. We can follow these steps to achieve this:
- Identify the hard drives in your computer by running this command:
sudo lsblk
You can identify the drive(s) by looking at their name, size, or type from the output of the command.
For example the hard drive maybe called:/etc/sdb1 - Create a mounting point for the drive to mount. For example, if the drive is used for data storage, it can be called ‘storage1’ if you like. For this example, it will be called ‘storage1’ under the root directory:
/storage1
Run the following command to achieve this:sudo mkdir -p /storage1: the-pjust means it will create non-exist parents directory when there is non. For example, if the directory you want is called:/etc/folder1/storage, then if folder1 is not exist, it will throw an error non-exist folder. If give-pargument, it will createfolder1on demand. - Temporarily mount the drive to the directory just created:
sudo mount /etc/sdb1 /storage1 - Change the ownership and permissions of the mount point to allow the group access. For example, the group is called:
shareGroup:sudo chown -R :shareGroup /storage1sudo chmod -R 775 /storage1
This will give the group members read, write and execute permissions. - Make the mount permanent: to make the mounting of the drive permanent after reboot, you need to edit the
/etc/fstabfile. First, find the UUID of the partition.sudo blkid: UUID stands for universally unique identifier, it is a 128-bit number used to identify objects or entities in computer systems. In linux, it is often used to identify storage devices. - Edit the fstab file using a text editor, vim will be used here:
sudo vim /etc/fstab: fstab contains information about the filesystems and their mount points.
Add a new line at the end of the file with the following format:UUID=your-uuid /storage1 ext4 defaults,nofail 0 2
: ext4 is the file system of your harddrive, it can be something else if your drive is not ext4 format. ‘nofail’ means telling the system do not report an error if the device is not present at boot, it is useful for external or removeable devices, to avoid the boot process get delayed or stopped. ‘0’ is the dump frequency, used by the ‘dump’ backup utility. A value of ‘0’ means that the filesystem will not be dumped. ‘2’ is the pass number used by ‘fsck’ utility, which checks and repairs the filesystem. Typically, value ‘1’ is used for root filesystem, ‘2’ or higher are used for other filesystem. Value ‘0’ means the filesystem will not be checked by fsck. - Test the configuration:
sudo mount -a
if there are no errors, your drive should mount automatically at the next boot.
Step 4:
If you want to set the permission as whenever new folders, subfolders, files created by any group memebers, and the new content still share the same permission for all other group memebers. It can be achieved using Access Control Lists (ACLs) and set the group ID (setgid) bit on the directory:
- Install ACL if not already:
sudo apt install acl - set group ownership of the directory:
sudo chown -R :shareGroup /storage1 - Set setgid bit:
sudo chmod g+s /storage1: theg+soption means ‘set the group ID (setgid)’. ‘g’ means group, ‘s’ means a special permission known as the ‘set user ID’ or ‘set group ID’ bit, depending on its placement in the permission string. Once this is set, the has the following effects on the directory:- Inheritance of the group ownership: any new files and directories created within that directory will inherit the group ownership of the parent directory, rather than the primary group of the user who created the file.
- Execution with group privileges: for executable files, setting the setgid bit means that when the file is executed, it runs with the privileges of the file’s group owner, rather than the privileges of the user executing.
- Set default ACLs:
sudo setfacl -d -m g:shareGroup:rwx /storage1sudo setfacl -d -m o::r /storage1
: these means set the shareGroup with read write execute permissions, and others to read permission.