Tutorial: Managing Users and Hostname on Ubuntu
1. Change Hostname
To change the hostname of your system:
-
Edit the hostname file:
bashsudo nano /etc/hostname
Replace the existing name with your new hostname.
-
Edit the hosts file:
bashsudo nano /etc/hosts
Update the line that starts with
127.0.1.1
to reflect the new hostname. -
Apply the changes:
bashsudo systemctl restart systemd-logind.service
2. Rename a User
To rename a user:
-
Rename the user:
bashsudo usermod -l new_username old_username
-
Rename the home directory (if needed):
bashsudo usermod -d /homes/new_username -m new_username
3. Give Sudo Privileges to a User
To add a user to the sudo group:
bash
sudo usermod -aG sudo username
4. Add a New User
To add a new user with a home directory in /homes
:
-
Create the directory (if it doesn't exist):
bashsudo mkdir -p /homes
-
Add the user:
bashsudo useradd -m -d /homes/new_user -s /bin/bash new_user
-
Set a password:
bashsudo passwd new_user
5. Set Permissions for Home Directories
Ensure home directories are secure:
-
Set permissions:
bashsudo chmod 700 /homes/new_user
-
Set ownership:
bashsudo chown new_user:new_user /homes/new_user
Summary
- Change hostname by editing
/etc/hostname
and/etc/hosts
. - Rename users with
usermod
. - Grant sudo access by adding the user to the
sudo
group. - Add new users with custom home directories in
/homes
. - Set appropriate permissions for security.
If you have any more questions or need further assistance, feel free to ask!