Wednesday, July 17, 2019

Creating your first Linux scripts

In this video, we will create several simple Linux scripts. While simple, these scripts highlight how to automate many of the tasks you may have for your environment.

HelloWorld.sh

The first script, HelloWorld.sh is created by using your favorite Linux text editor (I suggest nano or vi). The first line is the "shebang" or "hashbang" that is used by the system to identify which application to run the script with. In this case it is a bash script, but there are also perl, python, and other scripting languages, so the shebang is helpful to identify the correct script type.
The next two lines start with a pound sign or hash tag (#). These lines are comments and the pound sign is a way of telling the computer to ignore these lines. Comments can and should be used extensively to ensure future readers, including yourself, understand the goal and purpose of the lines in your script.
Lastly, the echo command simply writes out "Hello World!".

#!/bin/bash
# Created by Ed on 7/16/19
# Writes out Hello

echo "Hello World!"

Once the file is created, it needs to be marked as executable. We do this by running chmod +x HelloWorld.sh from the command line. Once it is marked as executable, we can run it by typing ./HelloWorld.sh (note the leading dot and slash before the name).

HelloVar.sh

This second script operates similar to the first, but uses variables. The script begins with the shebang and a few lines of comments. The sixth line assigns "HelloWorld!" to the variable named var - note that there are no spaces around the equal sign, this is important. Once the variable is assigned, we use echo to write out the value.
After we have shown how we can use variables, we then assign 2 more variables: timenow and computername. The commands date and hostname are called and the outputs are assigned to the appropriate variables. Once assigned, we finally use echo to write out the values, along with some descriptive text.

#!/bin/bash
# Created by Ed on 7/16/19
# Writes out Hello using variables

# Set the variable
var="Hello World!"

# Print out variable
echo "$var"

# Assign more variables
timenow="$(date)"
computername="$(hostname)"

# Write out other variables
echo "Current date and time: $timenow"
echo "Computer name: $computername"

Again, once saved we use chmod +x HelloVar.sh to mark the file as executable. Then we can call the script by typing ./HelloVar.sh from the command line.

HelloInput.sh

This third script uses the read command to request input from the user. The script starts with the shebang and several lines of comments before calling the read command. The read command will read in a single line of data from the user, and then save it into the variable name. The -p parameter tells read to echo out a prompt to the user, and then wait for input.

#!/bin/bash
# Created by Ed on 7/16/19
# Prompts user for input and outputs hello

# Ask the users name
read -p "Please tell me your name: " name

# Say hello
echo "Hello $name, would you like to play a game?"

When finished, set it as executable and run it. The script will ask for your name and then respond back by saying Hello specifically to you

--------- Challenge --------- 
Create a script that:
1. Prompts for a username
2. Creates the user
3. Sets the password to Password01 (see examples below)
   echo -e "'Password01'\n'Password01'" | passwd Tim -f
OR
   echo "Password01" | passwd --stdin Tim
4. Adds user to Marketing group

Save script as NewMarketingUser.sh
Run script as root (sudo) to confirm

--------- Challenge 2 ---------
Create a script that:
1. Prompts for a group name
2. Creates the group
3. Creates a group folder in /usr
4. Sets group permissions on folder

Save script as NewGroup.sh
Run script as root (sudo) to confirm

Sunday, July 14, 2019

Installing LED puck lights

I this video I will show how to install under cabinet lighting in the kitchen. This will use a set of low-voltage LED lights to place lighting where its needed.

Once placed, I will use a mixture of zip tie mounts and double-sided foam tape to hide the wires and make the setup "clean".



Shopping List:

6 pack LED puck lights - https://amzn.to/2JIotql

3 pack LED puck lights - https://amzn.to/2leFYWT

Double sided foam tape - https://amzn.to/2lgYNZB

Zip Ties and adhesive mounts - https://amzn.to/2ldIkoQ


Thursday, July 11, 2019

Creating group folders for Linux users 2: Creating directories and setting permissions

This is a 2 part series about creating shared folders for groups to use. In this second video we use mkdir, chgrp, and chmod to create our group directories and apply permissions.

Once created, we login as various users and confirm group members can read/write to the folders, while non-members cannot access the folders.







Great Linux study resource: https://amzn.to/2YPrV8X

Creating group folders for Linux users 1: Creating users and groups

This is a 2 part series about creating shared folders for groups to use. In this first video, we use useradd, passwd, groupadd, and usermod to create the users and groups, and assign passwords and group memberships.

Once created we use cat and tail to look at the /etc/passwd, /etc/shadow, and /etc/group files to view the changes being made.

Finally, we login as the different users to confirm they are working properly.







Great Linux study resource: https://amzn.to/2YPrV8X


Saturday, July 06, 2019

LAMP 04 - Installing PHP





In this final video we complete the installation of the LAMP stack by installing and configuring PHP. Once installed, we confirm the installation with a sample page and finally remove the page to secure our system.





CompTIA Linux+ Guide to Linux Certification: https://amzn.to/2YMdrH9

LAMP 03 - Installing MySQL




In this third video we go over the installation of MySQL server on our Linux system. We will go over several of the security options and show how to confirm the application is running properly.




CompTIA Linux+ Guide to Linux Certification: https://amzn.to/2YMdrH9

LAMP 02 - Installing Apache



In this second video, we continue our installation of the LAMP stack by installing the Apache web server.




CompTIA Linux+ Guide to Linux Certification: https://amzn.to/2YMdrH9

LAMP 01 - Installing Linux



In this first of four videos, we will install Ubuntu 18.04 in preparation for building out our LAMP stack. This video covers the the various options available when installing Ubuntu, as well as describing when and why they would be necessary.




CompTIA Linux+ Guide to Linux Certification: https://amzn.to/2YMdrH9