Ensure that you have followed all the instructions in the previous lab and have configured two networks: a host-only network and a NAT network, with DHCP enabled. Make sure that your VM is attached to these networks via two adapters.
Use the following commands inside your VM to see your IP configuration:
ip address show
ip address showYou should get an output that looks something like the following example. Your interface names and IP addresses will vary:
Make a note of the IP address of your Host-only adapter. In your host system (Windows), run the ping command to ensure that the IP address is reachable. Here is an example output from Windows Command Prompt:
C:\Users\User1>ping 192.168.56.101
Pinging 192.168.56.101 with 32 bytes of data:
Reply from 192.168.56.106: Destination host unreachable.
Reply from 192.168.56.101: bytes=32 time=1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.56.101:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0msC:\Users\User1>ping 192.168.56.101
Pinging 192.168.56.101 with 32 bytes of data:
Reply from 192.168.56.106: Destination host unreachable.
Reply from 192.168.56.101: bytes=32 time=1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.56.101:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0msIf this does not work, or your VM does not have an IP address assigned, you MUST troubleshoot and resolve this issue before continuing.
To verify that the SSH service is installed and running on your Linux VM, run the following commands:
sudo service ssh status
sudo service ssh statusIf the service is started and is active, you can proceed to the next step. If you do not have the ssh server installed, you may receive an error about the service unit not existing. Use this procedure to install the service in your Linux VM:
sudo apt update # this will update the local database of the latest available software from the repositories on the Internet sudo apt install openssh-server # Wait for the installation to complete # The following will configure the ssh server to start automatically on startup sudo systemctl enable ssh # The following command will start the ssh server service sudo service ssh start # check the status again to see if the service is active sudo service ssh status # If you have UFW firewall installed on your system, you also need to open port 22 sudo ufw allow 22
sudo apt update
# this will update the local database of the latest available software from the repositories on the Internet
sudo apt install openssh-server
# Wait for the installation to complete
# The following will configure the ssh server to start automatically on startup
sudo systemctl enable ssh
# The following command will start the ssh server service
sudo service ssh start
# check the status again to see if the service is active
sudo service ssh status
# If you have UFW firewall installed on your system, you also need to open port 22
sudo ufw allow 22The output should look something like the following screenshot:
On your host machine, launch CLI. In Windows, you are looking for cmd or for Command Prompt. Then, attempt to connect to your Linux through SSH using the following command:
# replace username with your first name, and the IP should be your Linux VM IP address of the host-only adapter ssh <username>@<IP> # Here is an example: ssh ali@192.168.56.101
# replace username with your first name, and the IP should be your Linux VM IP address of the host-only adapter
ssh <username>@<IP>
# Here is an example:
ssh ali@192.168.56.101If successful, you will be shown a SHA256 fingerprint for the remote system you are connecting to (only the first time you connect), and you will be asked if you want to continue to connect. You should select yes. Then you should be prompted for your password. If successful, you will be logged into your Linux VM shell. Here are example screenshots:
All of the remaining commands in this lab are to be run on your lab Linux server, in the remote access terminal window. Install the system resource monitoring tools and user programs that we will be using, which may not already be installed. The following commands can be used to install this software:
sudo apt update sudo apt install sysstat memstat sl fortune cowsay tree glances htop
sudo apt update
sudo apt install sysstat memstat sl fortune cowsay tree glances htopSet up the default home directory contents for new users that get created on this system. Make the following directories in /etc/skel:
Create a text file called /etc/skel/.bash_login with commands in it to add the games and personal bin to the user's PATH, and run fortune through cowsay on every login:
export PATH=$PATH:/usr/games:~/bin [ -f ~/.bashrc ] && . ~/.bashrc fortune|cowsay
export PATH=$PATH:/usr/games:~/bin
[ -f ~/.bashrc ] && . ~/.bashrc
fortune|cowsayExample commands to make those directories and create that file:
sudo mkdir /etc/skel/{bin,Documents,Pictures,public_html}
cat >~/.bash_login <<EOF
export PATH=$PATH:/usr/games:~/bin
[ -f ~/.bashrc ] && . ~/.bashrc
fortune|cowsay
EOF
sudo cp ~/.bash_login /etc/skelsudo mkdir /etc/skel/{bin,Documents,Pictures,public_html}
cat >~/.bash_login <<EOF
export PATH=$PATH:/usr/games:~/bin
[ -f ~/.bashrc ] && . ~/.bashrc
fortune|cowsay
EOF
sudo cp ~/.bash_login /etc/skelNext, we will create a personal account to use. It will be created using your own name. Do not use special characters such as dashes, spaces, or apostrophes. The full name can be mixed case (e.g. First Last), but use only lower case when entering your username for the account. The account username must be your first name. Refer to the Ubuntu Server Guide if necessary for more information on managing user accounts.
sudo adduser <firstname>
sudo adduser <firstname>Add your user account to the sudo group, so you can use sudo from it. The command will look similar to this:
sudo adduser <firstname> sudo
sudo adduser <firstname> sudoSet a secure password on your account using passwd firstname. For the remaining labs this semester, log onto your server using the account you just created. Log out of the ubuntu account, and log in to your new personal account.
Verify you can run the following commands:
memstat sl fortune iostat sudo ss -tlpn
memstat
sl
fortune
iostat
sudo ss -tlpnUse the df -h command to see how much free space you have on your server. Review the descriptive first paragraph of the man page for each of the commands on the slides from the presentation. Try each of the id, who, w, last, du, mount, lshw, lspci, lsusb, lscpu, ps, vmstat, prtstat, ss, top, dpkg commands on your VM.
Download the server-check.sh script from github as directed in Lab 00 and run it for the first lab:
sudo /root/server-check.sh -l 1 firstname lastname studentnumber
sudo /root/server-check.sh -l 1 firstname lastname studentnumber