Introduction to Basic Linux System Administration using Oracle Virtual Box
How do i change our user account that we are working under to root
root has all powers
In Linux and Unix-like systems, you can change to the root user (superuser) by using the su (substitute user) or sudo (superuser do) commands. The method depends on the configuration of your system. Below are the general instructions for both methods.
Method 1: Using the su Command
You will be prompted to enter the root password. Type the root password and press Enter. If the operation is successful, the prompt will change, typically to a # sign, indicating that you are now operating as the root user. Method 2: Using the sudo Command
If your user account is configured to allow sudo access, you can use the sudo command to execute individual commands as the root user or start a root shell session.
To execute a single command as the root user:
Type sudo followed by the command you want to execute as root. bashCopy code
sudo <command>
For example, to update the package list, you might use: bashCopy code
sudo apt update
Enter your user password when prompted. I added user psigurd how do I make psigurd a root user
To grant a user root privileges, you can add them to the sudo group (on systems where the sudo group is configured with root privileges) or specify them in the sudoers file. Below are the steps for both methods:
Adding User to sudo Group:
This method works for distributions like Ubuntu, where members of the sudo group are granted sudo privileges by default.
Use the following command to add the user psigurd to the sudo group: sudo usermod -aG sudo psigurd Enter your password if prompted. After this, the user psigurd should have sudo privileges. To use these privileges, psigurd will need to prefix commands with sudo and enter their password when prompted.
Adding User to the sudoers File:
If you want to explicitly grant psigurd sudo privileges in the sudoers file, follow these steps:
Type the following command to edit the sudoers file: This command opens the sudoers file in the default system text editor. In the editor, navigate to the section of the file that looks like this: # User privilege specification root ALL=(ALL:ALL) ALL Below this section, add the following line to give the user psigurd the same privileges as the root user: psigurd ALL=(ALL:ALL) ALL Save the file and exit the editor. If you are in vi editor, press Esc key, then type :wq and press Enter. If you are in nano editor, press Ctrl + X to exit, then Y to confirm the changes, and Enter to save. Now, the user psigurd should be able to execute commands with sudo privileges. To verify, you can switch to psigurd and try running a command with sudo:
bashCopy code
su - psigurd
sudo ls /
The user will need to enter their password to use sudo.
Important Note:
Be cautious while performing these operations. Granting a user sudo privileges provides them with significant control over the system, allowing them to execute any command as the root user. Ensure you trust the user and that they understand the responsibilities and risks associated with these privileges.
Instructions to make a group and add users to that group
Below are instructions on how to create a new group and add users to this group, then give the group sudo (root) privileges. These steps are generic and should work on most Unix-like systems.
Step 1: Creating a New Group
Use the following command to create a new group named adminusers: Step 2: Adding User to the New Group
Add users to this new group using the following command. Replace username with the name of the user you want to add to the adminroot group:
bashCopy code
sudo usermod -aG adminusers username
For example, to add a user named psigurd to the adminusers group, use:
bashCopy code
sudo usermod -aG adminroot psigurd
You can repeat this step for any other users you wish to add to the adminroot group.
Step 3: Giving the New Group Sudo Privileges
To give the adminroot group sudo privileges, you need to edit the sudoers file:
Type the following command to edit the sudoers file: In the editor, scroll down to the section that looks like this (this section might look slightly different or be located at different places depending on your distribution): # User privilege specification root ALL=(ALL:ALL) ALL Below this section, add the following line to grant all members of the adminroot group sudo privileges: %adminroot ALL=(ALL:ALL) ALL The % symbol before the group name specifies that this line applies to a group rather than an individual user. Save the file and exit the editor. If you are in vi editor, press Esc, then type :wq, and press Enter. If you are in nano editor, press Ctrl + X to exit, then Y to confirm the changes, and Enter to save. Step 4: Testing the Configuration
To test the new configuration:
Switch to a user in the adminroot group. If you added psigurd to adminroot, you can switch to this user by typing: Try executing a command with sudo: The user should be able to execute the command with sudo privileges, and will be prompted to enter their password. Important Note:
Be careful when editing the sudoers file and assigning sudo privileges. Incorrect settings can lead to security risks and system instability. Ensure you understand the implications of the changes and the responsibilities of users with sudo access.
In Linux, you can list users and groups using various commands. Below are a few methods:
To List Users:
1. Using the getent command:
bashCopy code
getent passwd
This command will list all users in the system along with their information such as home directory and default shell. The output will look similar to this:
plaintextCopy code
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
...
Each field is separated by a colon (:). The first field is the username.
2. Using the cut command:
bashCopy code
cut -d: -f1 /etc/passwd
This command reads the /etc/passwd file and cuts out the first field (-f1) from each line. The fields are delimited by a colon (-d:), which is specified in the command. This will give you a list of all user names on the system.
To List Groups:
1. Using the getent command:
bashCopy code
getent group
This command will list all the groups on your system along with the group members. The output will look similar to this:
plaintextCopy code
root:x:0:
daemon:x:1:
...
Again, each field is separated by a colon (:), and the first field is the group name.
2. Using the cut command:
bashCopy code
cut -d: -f1 /etc/group
This command reads the /etc/group file and cuts out the first field (-f1) from each line. Like the command above, the fields are delimited by a colon (-d:), which is specified in the command. This will give you a list of all group names on the system.
To View Users in a Specific Group:
Replace groupname with the name of the group.
bashCopy code
getent group groupname
This will list the information for the specified group, including all members of the group.
Note:
You might need superuser privileges to view this information. If you are having trouble, try prefixing the commands with sudo. The getent command may not be available on all systems by default.
To start a root shell session:
Type sudo -i or sudo su and press Enter. Enter your user password when prompted. This will start a new shell session as the root user. The prompt will typically change to a # sign, indicating that you are operating as the root user. Note:
Be very cautious when operating as the root user or executing commands with sudo, as you have the ability to make critical changes to your system, including ones that can make the system unusable. It's generally a good practice to use sudo for individual commands rather than working in a root shell session, as it reduces the chance of inadvertently making harmful system changes. Always exit the root session after completing your tasks by typing exit and pressing Enter to return to your normal user session.
How to put vboxuser in the sudoers file
Adding a user to the sudoers file allows the user to execute commands with superuser privileges, which is essential for performing administrative tasks on a Linux system.
Below are the steps to add a user (in this case, vboxuser) to the sudoers file.
Using the usermod Command:
On many Linux distributions, you can add a user to the sudo group, which is often listed in the sudoers file as allowed to execute commands as the superuser.
Enter the following command: bashCopy code
sudo usermod -aG sudo vboxuser
This command adds the vboxuser to the sudo group, granting them sudo privileges.
Editing the Sudoers File Directly:
You can also directly edit the sudoers file to add the user.
Type the following command to edit the sudoers file. This command uses the visudo utility, which opens the sudoers file in the system's default text editor (typically vi or nano), and performs syntax checking on modifications. bashCopy code
sudo visudo
In the editor, navigate to the section of the file that looks like this: plaintextCopy code
# User privilege specification
root ALL=(ALL:ALL) ALL
Below this section, add the following line: plaintextCopy code
vboxuser ALL=(ALL:ALL) ALL
This line allows the vboxuser to run all commands with sudo privileges on all hosts.
Save the file and exit the editor. If you are in vi editor, press Esc key, then type :wq and press Enter to save and exit. If you are in nano editor, press Ctrl + X to exit, then Y to confirm changes, and Enter to save. Verify the Configuration:
To ensure vboxuser now has sudo access, you can switch to vboxuser and try running a command with sudo.
bashCopy code
su - vboxuser # switch to vboxuser
sudo ls / # try to list the root directory
You should be able to execute the command without any permission errors. Remember that the vboxuser will need to enter their password to use sudo, unless password prompts for sudo have been disabled in the sudoers file.
Important Note: Be cautious while performing these operations. Incorrect settings in the sudoers file can potentially lock you out from the system or give unauthorized users elevated privileges.
what is the default password for new ubuntu install on oracle virtual box
For password, try changeme
Once you are installed: Software Catalog:
Visual Studio Code
In a fresh Ubuntu installation on Oracle VirtualBox, there shouldn't be a default password set.
During the installation process of Ubuntu, you're usually prompted to create a user and set a password for that user. This user will have sudo privileges, meaning you can perform administrative tasks by providing the password you set during installation when prompted.
If you're using a pre-built VirtualBox image (also known as an "appliance" or "VM") that someone else created, the default username and password would be set by the person who created the image. Often, the default username is ubuntu and the default password is either password or ubuntu, but this is not always the case. If you're using such an image, you should refer to the documentation or website where you downloaded the image to find out the default login credentials.
If you can't find the default password, you could reinstall Ubuntu on your virtual machine and set your own password during installation, ensuring that you have the credentials you need to log in and administer the system.
If you've forgotten the password for an account on your Ubuntu Virtual Machine, you can reset it by booting into recovery mode and using the passwd command to set a new password. Here's how you can do it:
Restart the Ubuntu VM in Oracle VirtualBox. As the VM starts, hold down Shift to access the Grub boot menu. In the Grub boot menu, select the "Advanced options for Ubuntu" and press Enter. Select "Recovery mode" and press Enter. In the Recovery Menu, select the "root" option to drop into a root shell prompt. You'll be in a read-only filesystem, remount it as read/write with the command: mount -o rw,remount / Now use the passwd command to change the password for the desired username: passwd username Follow the prompts to enter a new password for the user. Type exit to leave the root shell prompt. Select "resume" in the Recovery Menu to boot the system normally. Now you can log in with the new password you've set.
Objective
This workbook will guide level 1 students through the process of installing a Linux operating system under Oracle Virtual Box, creating users, and setting permissions to the file system.
After completing this guide, students will have a fundamental understanding of basic Linux system administration tasks.
Prerequisites
A computer with Oracle Virtual Box installed A Linux ISO file (for this guide, we will use Ubuntu) Lab Outline
Installation of Linux on Oracle Virtual Box File System and Directory Management Step 1: Installation of Linux on Oracle Virtual Box
Open Oracle Virtual Box and click on “New” to create a new virtual machine. Name your VM, select “Linux” as the type, and choose the version that corresponds to your Linux ISO (e.g., Ubuntu). Allocate at least 2GB of RAM and create a virtual hard disk. Mount the Linux ISO file by going to Settings > Storage, then click on the empty disk icon and browse to your Linux ISO file. Start the virtual machine and follow the prompts to install Linux. Step 2: Basic Linux Commands
Open the terminal in your Linux virtual machine. Familiarize yourself with basic commands by typing man intro to access the introductory manual page. Practice commands like ls (list), cd (change directory), pwd (print working directory), and man (manual). Step 3: User Management
In the terminal, type adduser <usernamsudo e> to create a new user. Follow the prompts to set a password and other information. Type sudo deluser <username> to delete a user. Use sudo adduser <username> sudo to add a user to the sudo group, giving them administrative privileges. Step 4: File System and Directory Management
In the terminal, practice navigating the file system using cd, ls, and pwd. Create directories using mkdir <directory_name> and files using touch <file_name>. Delete directories and files using rmdir <directory_name> and rm <file_name> respectively. Step 5: Setting Permissions
Use ls -l to view file and directory permissions. Change permissions with chmod. For example, chmod 755 <filename> sets read, write, and execute permissions for the owner, and read and execute permissions for others. Use chown to change file ownership, e.g., sudo chown <username>:<group> <filename>. Conclusion:
This lab provides basic exposure to Linux system administration under Oracle Virtual Box. Practice the skills learned in this guide to gain more confidence in navigating and managing Linux systems. For more advanced tasks, refer to the Linux man pages and other online resources.
Below are five exercises that you can use to get some hands-on practice with PowerShell scripting. Each exercise builds on skills that are fundamental for PowerShell scripting, such as working with variables, loops, and conditions, and performing operations on strings and files.
Exercise 1: Hello, World!
Objective: Write a simple PowerShell script to print "Hello, World!".
Open PowerShell ISE or any text editor. Write the following code: powershellCopy code
Write-Output "Hello, World!"
Save the file with a .ps1 extension, for example, hello.ps1. Run the script in PowerShell. Exercise 2: Variables and Input
Objective: Write a script to ask the user for their name and then print a greeting message using that name.
Create a new PowerShell script file. Write the following code: powershellCopy code
$name = Read-Host "What is your name?"
Write-Output "Hello, $name!"
Save and run the script to see the output. Exercise 3: Working with Loops
Objective: Create a script to print numbers from 1 to 10 using a loop.
Create a new PowerShell script file. Write the following code: powershellCopy code
for ($i = 1; $i -le 10; $i++) {
Write-Output $i
}
Save and run the script to see the output. Exercise 4: Working with Files
Objective: Write a script to create a new text file, write some text to it, and then read the text from the file.
Create a new PowerShell script file. Write the following code: powershellCopy code
# Specify the file path
$filePath = "C:\temp\sample.txt"
# Write text to the file
"Hello, PowerShell!" | Out-File -FilePath $filePath
# Read and display the text from the file
Get-Content -Path $filePath
Save and run the script to see the output. Exercise 5: Error Handling
Objective: Create a script that tries to read a non-existent file and handles the error by printing a custom error message.
Create a new PowerShell script file. Write the following code: powershellCopy code
try {
# Attempt to read a non-existent file
Get-Content -Path "C:\non_existent_file.txt"
}
catch {
# Handle the error by displaying a custom message
Write-Output "An error occurred: $_"
}
Save and run the script to see the output. Each of these exercises will help solidify your understanding of PowerShell scripting, providing a good foundation for more complex scripting tasks in the future.
In this lab, you’ll set up an HTTP server on your Linux machine using Apache, one of the most popular web servers available.
Prerequisites:
A Linux server (a virtual or physical machine) Basic knowledge of Linux commands and the terminal Superuser (root) access on the server Lab Outline:
Install Apache HTTP Server Configure Firewall to Allow HTTP Traffic Detailed Steps:
1. Update Your System
Before you begin, it’s a good practice to make sure your system package repository is up to date. Open a terminal window and type the following command:
For Ubuntu/Debian based systems:
bashCopy code
sudo apt update && sudo apt upgrade
For RedHat/CentOS systems:
bashCopy code
sudo yum update
2. Install Apache HTTP Server
On Ubuntu/Debian:
bashCopy code
sudo apt install apache2
On RedHat/CentOS:
bashCopy code
sudo yum install httpd
3. Configure Firewall to Allow HTTP Traffic
To allow traffic on port 80, you'll need to update your firewall settings:
On Ubuntu/Debian with UFW:
bashCopy code
sudo ufw allow 'Apache'
sudo ufw reload
On RedHat/CentOS:
bashCopy code
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
4. Start and Enable Apache Server
On Ubuntu/Debian:
bashCopy code
sudo systemctl start apache2
sudo systemctl enable apache2
On RedHat/CentOS:
bashCopy code
sudo systemctl start httpd
sudo systemctl enable httpd
5. Test the HTTP Server
Now that the server is running, open your web browser and type the IP address of your Linux server. You should see the default Apache welcome page.
arduinoCopy code
http://your_server_ip
6. Create a Basic Web Page
Let's create a simple HTML file to serve. On the server, navigate to the web root directory and create a new file named index.html: On Ubuntu/Debian:
bashCopy code
cd /var/www/html
sudo echo "<h1>Welcome to My Web Server!</h1>" | sudo tee index.html
On RedHat/CentOS:
bashCopy code
cd /var/www/html
sudo echo "<h1>Welcome to My Web Server!</h1>" | sudo tee index.html
Save the file and revisit your server's IP address in the web browser: arduinoCopy code
http://your_server_ip
You should now see your basic web page displaying the message: "Welcome to My Web Server!"
Conclusion:
You have successfully set up and configured an Apache HTTP server on your Linux server and served a basic HTML page. As you continue to explore web server administration, consider learning about other server software like Nginx, and also learn about HTTPS and how to secure your web server using SSL/TLS certificates.
November 13 Lab work: User Administration
Lab Workbook: Managing Users and Resources on Kali Linux Using Python