bookmark_borderWorking with UFW – Uncomplicated Firewall – on Ubuntu

This is not a comprehensive guide to the UFW application.

It is a basic orientation for the UFW application. This should provide insights you’re probably not aware of, but many might assume you already know.

Continue reading “Working with UFW – Uncomplicated Firewall – on Ubuntu”

bookmark_borderHow to Auto-Update CentOS 7 Packages with Yum-Cron

If you’re looking for a quick way to keep your CentOS machine patched at all times, become friends with yum-cron.

To install, in terminal, use:

#yum -y install yum-cron

The -y forces the install, answering any Yes / No “are you sure” questions.

Once installed, be sure to start the service using:

# systemctl start yum-cron.service

You can verify the status (make sure it’s running) using:

# systemctl status yum-cron.service

Output should look something like:

yum-cron.service – Run automatic yum updates as a cron job
Loaded: loaded (/usr/lib/systemd/system/yum-cron.service; enabled; vendor preset: disabled)
Active: active (exited) since Mon 2016-11-07 19:16:01 UTC; 2s ago
Process: 5385 ExecStart=/bin/touch /var/lock/subsys/yum-cron (code=exited, status=0/SUCCESS)
Main PID: 5385 (code=exited, status=0/SUCCESS)

Last step is to make sure it’s enabled, this will make sure it restarts in the event the machines reboots later.

# systemctl enable yum-cron.service

Sharing is caring!

bookmark_borderHow do you add color or bold the echo outputs in a shell script?

If you’re working in linux you will be introduced to writing shell scripts at some point. When you do, you’ll become very familiar with the echo.

If you open your terminal, and run an echo command it’ll literally echo whatever you put after the echo:

$ echo "Hello World" Hello World
Continue reading “How do you add color or bold the echo outputs in a shell script?”

bookmark_borderTar (Compress) a Directory without Images via Terminal

Sometimes you need to compress an entire directory, but sometimes you want to ignore specific file types.

Here is a basic command that you can use to remove specific file types before you compress it. In this example we use the find command to look for, and ignore, all image file types. That then gets piped into the tar command:

Continue reading “Tar (Compress) a Directory without Images via Terminal”

bookmark_borderSetting Root Password on MySql when it’s Empty

I was working on one of my servers when I realized that I had done a bone-head mistake. I left the root password blank in MySQl. 

It was not as easy as I thought to fix the problem. There were a couple of things I didn’t account for, specifically that when you’re initially setting up MySQL on Ubuntu and don’t provide a password to the root user, it will use the auth_socket plugin. That plugin doesn’t care and doesn’t need a password. It just checks if the user is connecting using a UNIX socket and then compares the username.

Continue reading “Setting Root Password on MySql when it’s Empty”

bookmark_borderHow do you show and update a MySQL database in a linux terminal?

This post will walk you through the process of showing and updating a MySQL database via terminal.

We’ll use a WordPress installation because it has an established database schema. The principles apply to any database.

Continue reading “How do you show and update a MySQL database in a linux terminal?”

bookmark_borderHow do you enable SFTP on your Ubuntu server?

SFTP is a file transfer protocol. It wraps the File Transfer Protocol (FTP) inside the Secure Shell (SSH) protocol. This allows the communication to be protected as it moves from one point to another.

PSA: Using FTP is considered an insecure transfer protocol and should be avoided.

This article assumes you are trying to create new SFTP users on your linux machine. In this example we’ll be using Ubuntu 18.04.

Enabling and Creating SFTP users:

To enable SFTP you have to enable it inside your SSH configuration file. It’s often located here: /etc/ssh/sshd_config. Open the file and add the following to the end of the configuration file:

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server
Match group sftp
X11Forwarding no
AllowTCPForwarding no
ForceCommand internal-sftp

Options explained:

OptionDescription
SubsystemAn abstraction layer that allows you to invoke remote commands. In this instance, we’re invoking sftp-server.
MatchAllows you to limit actions in shell, in this instance we’re limiting the actions to a specific group – sftp. Only those users inside the SFTP group will be able to SFTP into the server.
X11ForwardingThis is a special case for remote tunneling. Unfortuantely it can be used maliciously by a bad actor, so it’s recommended your disable unless you know what you’re doing.
AllowTCPForwarding“TCP Forwarding” allows you to encapsulate any other protocol (based on TCP of course) inside an already established SSH connection. There are a lot of reasons for this, but we don’t want to allow SFTP users to use this without appropriate planning.
ForceCommandThe remote system can only execute a set of statically defined commands. Specifying a command of internal-sftp will force the use of an in-process SFTP server that requires no support files when used with ChrootDirectory.

Once you add this to the SSH config file you need to restart OpenSSH:

service ssh restart

Now you need to add new SFTP users, and apply the user to the right group.

useradd -m [newsftpuser] -g sftp

Set the password:

passwd [newsftpuser]

Now you can test your SFTP connection, from a different server:

sftp [newsftpuser]@[serverIPaddress]

Happy SFTP’ing!

Sharing is caring!

bookmark_borderCan you move files types from one location to another in linux?

There are instances where you want to quickly locate and move specific file types from point A to Point B.

Example:

Move all PHP files from /home/$user/php-files/ to /home/$user/php-mv-files

Easiest way to do this is to use the Find command in terminal.

$ find ./ -name "*.php"

./php-files/file3.php
./php-files/file2.php
./php-files/file1.php

This lists all the PHP files in the /php-files directory.

To move the files, you run the following command:

$ find ./php-files/ -name "*.php" -exec mv {} ./php-mv-files/ \;

This will move all files from ./php-files to ./php-vmv-files. Running the original Find command will get you the following:

$ find ./ -name "*.php"
./php-mv-files/file3.php
./php-mv-files/file2.php
./php-mv-files/file1.php

In this instance, -exec mv {} says, run the MV command on the files selected from the original find, that’s what the {} implies. You then escape, and close the command using \;. This final piece is critical to stopping the command.

Sharing is caring!

bookmark_borderHow do you add something to the Path environmental variable?

Path environmental variables are variables that function like a shortcut for your system. They allow you to define directories where executables are located.

Assume you installed this application picc-9.82.9453-linux.run. Without setting the path you’d have to run this every time in your terminal:

# /usr/hitech/picc/9.82/bin/picc

Instead of:

# picc

Running picc without having to define the path every time is so much easier, and faster. To achieve this experience you have to add the application executable to the Path environmental variable.

The first option is edit your user profile:

$ vim ~/.bash_profile

It will look something like this:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

You are looking to edit this section:

PATH=$PATH:$HOME/bin

Update the path with new application location (e.g., /usr/hitech/picc/9.82/bin) using the colon (:) as the separator.

PATH="$HOME/bin:$PATH:/usr/hitech/picc/9.82/bin"

Save the file, and try running the command in your terminal.

# picc

Sharing is caring!