cp Command to Overwrite Without Confirmation

I’m used to running the cp command in Linux often. But, this time a client had an emergency and I needed to use the cp command to overwrite a directory in their Red Hat Linux box.

I needed to login with root for this one. I needed to restore a directory to it’s original location using the cp command to overwrite the old corrupted one. In the terminal I ran:

cp -rf /data/restore/restored-dir/var/www/cms/ubi /var/www

And got prompted to confirm the overwrite for each file:

cp: overwrite ‘./ubi/index.html’?

It sucks to have to confirm thousands of files even when you’re logged in as root! Why? I ran to the kitchen and brew myself a nice cup of coffee from Guatemala.

Then, I found out that root in Red Hat Linux has an alias for the cp command:

which cp

and got:

which cp comamnd

In order to escape this alias in Linux I had to run the same command previously, but with an added ‘ / ‘ in front of the cp command:

/cp -rf /data/restore/restored-dir/var/www/cms/ubi /var/www

Now, all works. I was able to copy the restored files.

You can always contact me if you have any questions. Also, make sure to visit my coffee mugs and T-Shirts shop for inspiration.

Change MariaDB Data Directory Location CentOS

A client asked me if I can help their WordPress developer configure a development Linux box. They created a separate partition and wanted to change their MariaDB Data Directory Location on their CentOS server.

After taking a walk in New York City by the Madison Square Park I decided to put this tutorial together. There are some simple steps:

  1. Moving MariaDB Data Directory
  2. Pointing to the New Data Location
  3. Restart MariaDB

Moving MariaDB Data Directory

We need to verify the the current MariaDB data location first. Login using the below command. Enter your password when prompted:

mysql -u root -p

Then, once logged in run the following:

select @@datadir;

You should see the current location:

Change MariaDB Data Directory
MariaDB data location

Type exit.

Next, stop MariaDB:

sudo systemctl stop mariadb

Confirm it really stopped:

sudo systemctl status mariadb

Read the output and make sure it says:

Stopped MariaDB database server.

Point to the New Data Location

Now, we need to tell MariaDB where the new location will live. Edit /etc/my.cnf by running:

sudo vim /etc/my.cnf

Find the line that begins with ‘datadir=’ and make the changes to the new location. Also, change the ‘socket=’ if necessary.

Remember, you can also define a custom .cnf in side the /etc/my.cnf.d/ 

Write your above changes and now let go start MariaDB and see.

Finally, start MariaDB by running this command:

sudo systemctl start mariadb

Verify its running:

sudo systemctl status mariadb

Also, repeat the first command above:

mysql -u root -p
select @@datadir;

In order to verify the changes. Type exit or \q.

Cheers! Remember to see my T-shirt and coffee mugs shop. I designed some inspirational ones. Let me know what you think.

Hope you enjoy this Change MariaDB Data Directory brief tutorial.

Setup Windows 11 without a Microsoft Account

I found myself configuring for the first time a new Windows 11 laptop for a client. I was used to configure the initial account in other Windows versions as a local user. This time the setup of Windows 11 without a Microsoft account was very tricky.

After having a beer in one of my favorite bars in New York city I found a way to get around this confusing setup.

I tried the old fashion way to manage Windows users and I ran:

lusrmgr.msc

I got the usual screen which is funny because this is Windows 11 and NOT Windows 10. See what it says on the Local Users and Group screen:

lusrmgr.msc window in Windows 11

Finally, I found a quick way to setup Windows 11 without a Microsoft account.

Windows 11 without Microsoft account
New user screen Windows 11

I like the command prompt in either Windows or Linux or whatever system I touch.

At the setup screen in Windows press Shift + F10 shortcut. This will open a command prompt. Next, we need to release the network configuration we setup in the previous screen by running this command:

ipconfig /release
Windows 11 without Microsoft account
ipconfig /release command Windows 11

Quickly click on the Back button/arrow. Windows will now show you the ‘Who’s going to use this device?’ screen. This will be a local user. Enter your desired username, press Next and then enter a password for this new local user. You will be prompted for the usual privacy settings.

Enable SSH using the Terminal on macOS

The other day I was helping a client with her mac. Suddenly, Finder crashed and I ended up with just the Terminal open. This is what forced me to enable SSH using the Terminal. I decided to brew a great cup of Bourbon coffee first.

To enable SSH using the Terminal is quite simple. It requires sudo privileges. First, I wanted to check if SSH was already enabled by running this command:

sudo systemsetup -getremotelogin
Enable SSH using Terminal
Results Terminal showing ON

After confirming SSH was NOT enabled I ran the following command to turn ON SSH in this macOS:

sudo systemsetup -setremotelogin on

Remember when using sudo you need to enter your password because it requires administrator rights.

As always, contact me if you have any questions. Also, remember to visit my IT Handyman shop. I make all the designs. Thank you!

How to find Python shell executing in 32bit or 64bit

I was a little confused about how find Python shell executing in 32bit or 64bit. After taking a walk by the Buskwick Inlet Park in NYC I decided to look into this.

I found a simple and quick way to find if my Python shell is executing in 32bit or 64bit. I’m using a macOS in this case, but this should work on any Linux distro.

These are the simple steps I took:

1. Started the Python interpreter
2. Ran the following:
   import platform
   platform.architecture()[0]

The above should display the following output:

'64bit' or '32bit'
Python shell executing in 32bit or 64bit
Python shell interpreter

Manage Linux Users with the passwd command

To manage Linux users with the passwd command is very handy and straight forward. After brewing a really good Colombian coffee at home from Finca La Camelia I decided to put this brief tutorial.

passwd command options

passwd -S <username>

This option displays the status of a specific user. Example output:

username PS 2022-06-13 0 99999 7 -1 (Password set, SHA512 crypt.)

In the above example it shows that username was created June 13, 2022 with a SHA512 encryption.

passwd -l <username>

The above option with -l will lock the username above. This only locks access to the system, but the user can still login if he/she has SSH access set with a public key.

passwd -u <username>

With the -u option above you will ‘unlock’ the username that was already in ‘locked’ state with the -l option.

passwd -d <username>

The above will delete a password for username.

passwd -e <username>

To expire an account immediately use the above option -e. This option will force username to change their password at next login.

passwd -n 10 username

The above indicates the username cannot change their password until 10 days have gone by.

passwd -x 90 username

The above tells the Linux system that username that after 90 days the password will expire forcing the username to change their password.

Hopefully this short tutorial can point you to the right direction. You can always contact me if you have any questions. Also, check out my shop for unique coffee mugs and t-shirt designs I created. There are more options to manage Linux passwd command, but these are the most common ones. I will be adding more options soon.

Create a New Linux Superuser Admin User

The other day I had to add a sudo user in Linux. I have done this many times in Ubuntu/Debian Linux boxes, but forgot how to create a new Linux superuser in RedHat/CentOS/Fedora family.

I created this quick review and maybe can help others.

Create New Linux Superuser in Ubuntu/Debian

Let’s do this using the Terminal/Command-line way. Open your terminal and type:

sudo adduser newuser

The newuser is the name of the new user you’re trying to create.

The above command will create the new user. Now, you need to add the newuser to the sudo group. Type the next command in your terminal:

sudo usermod -aG sudo newuser

Little explaination about the above -a means to Append and G stands for Group.

When you’re done adding the user to the sudo group, you should verify by running this command in your terminal:

groups newuser

You should see the sudo group listed.

You can also do the first two commands in one shot:

sudo adduser newuser sudo

Linux is cool! Brew coffee at home is ever better! 🙂

Create New Linux Superuser in RedHat/CentOS

Using RedHat 8 at one of my clients. I haven’t touch this Linux disto in a while, but its no big deal. I took a walk by Pier 76 in NYC before handling this one.

Create a new user you need the adduser command:

adduser newuser

Next, set a password for the newuser:

passwd newuser

Last, you need to add the newuser to the wheel group:

usermod -aG wheel username

Now, if you haven’t open the sudoers file using this command:

visudo

Edit the line %wheel ALL(ALL) by removing the ‘#’ character in front of it. There might be other options for the wheel group let say you can add or un-comment this line:

%wheel  ALL=(ALL)       NOPASSWD: ALL

This will allow the users in the wheel group to run sudo without having to enter their password every time.

Hope you like this brief tutorial. You can always contact me if you have any questions. Also, check out my T-Shirts and coffee mugs shop. I made all the designs.

Setup Apache Virtual Hosts on Red Hat 8

Last week a client asked me to setup a dev and production environments on their new Red Hat 8 box. I have setup Apache virtual hosts in Ubuntu in the past. I knew to setup Apache virtual hosts on Red Hat 8 should not be that difficult.

This is when I decided to take a walk by Pier 76 in New York City to recharge by brain.

First, make sure you have installed Apache in your Linux box, you’re logged in as root or a user with sudo and you’re pointing your domain name to your server’s public IP.

Create Your Directory Structure

This is called the document root for your site files. This can be set in any location in your Linux server, but we normally follow this structure example:

/var/www (this is the path for your web files)
├── cgi-bin
├── dev.yoursite.com
│   └── html
│       └── index.html
├── html
└── prod.yoursite.com
    └── html

dev.yoursite.com and prod.yoursite.com are the two directories for your Apache server to serve your website from. We created another /html directory under each domain path. This is where your files will live.

Next, change the ownership of each document root. For example:

sudo chown -R apache: /var/www/dev.yoursite.com
sudo chown -R apache: /var/www/prod.yoursite.com

Apache by default loads all configuration files that end in .conf as the file extension inside the directory /etc/httpd/conf.d/

Next, using your favorite editor create a virtual host file inside /etc/httpd/conf.d/ directory. For example. dev.yoursite.com.conf:

<VirtualHost *:80>
    ServerName dev.yoursite.com
    ServerAlias www.dev.yoursite.com
    ServerAdmin webmaster@dev.yoursite.com
    DocumentRoot /var/www/dev.yoursite.com/html
    <Directory /var/www/dev.yoursite.com/html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>
    ErrorLog /var/log/httpd/dev.yoursite.com-error.log
    CustomLog /var/log/httpd/dev.yoursite.com-access.log combined
</VirtualHost>

Now, test the configuration file using this command:

sudo apachectl configtest

If everything is good and there are no syntax errors. You will get:

Syntax OK

Then you need to activate the new virtual host by running this command in your Linux terminal:

sudo systemctl restart httpd

Visit your site by name or IP using your browser and let me know if all works.

Run traceroute on macOS Terminal and Understand the Results

The other day a client was having issues reaching a couple of websites from within their office environment. Our good command line utility traceroute came to the rescue. I used to run this command back in the days when mainly using Windows. Luckily, we can run traceroute in macos terminal.

I had to brew another Peruvian coffee from Quillabamba before taking on this one.

Running traceroute is quite simple. Here is an example:

traceroute badsite.com
traceroute to badone.com (35.186.238.101), 64 hops max, 52 byte packets
 1  192.168.3.1 (192.168.3.1)  7.997 ms  5.438 ms  6.629 ms
 2  160.72.69.169.lightower.net (160.72.69.169)  9.057 ms  7.249 ms  8.644 ms
 3  160.72.248.44.lightower.net (160.72.248.44)  5.649 ms  8.158 ms  7.375 ms
 4  ae10-nycmnyzrj93.lightower.net (144.121.35.40)  8.217 ms  16.325 ms  5.153 ms
 5  et-0-0-22.edge2.newyork6.level3.net (4.30.181.125)  6.437 ms  8.161 ms  7.309 ms
 6  209.85.149.162 (209.85.149.162)  6.324 ms  6.192 ms
    google-level3-newyorkcity6.level3.net (4.68.75.170)  8.562 ms
 7  108.170.248.1 (108.170.248.1)  9.728 ms
    108.170.225.4 (108.170.225.4)  9.944 ms
    108.170.248.1 (108.170.248.1)  11.364 ms
 8  216.239.43.155 (216.239.43.155)  7.779 ms
    142.251.65.111 (142.251.65.111)  8.163 ms
    142.251.60.227 (142.251.60.227)  7.757 ms
 9  101.238.186.35.bc.googleusercontent.com (35.186.238.101)  7.223 ms  7.054 ms  7.531 ms

The results are divided into 3 sections:

  1. Number of hops: Indicates how many routers traceroute command was able to query. Usually the first one is your local router.
  2. Domain name: Show the URL and IP address of the router where your request passed by. This can vary by location. Sometimes it can even show an airport code.
  3. Round-Trip Times (RTT): This one is shown from the 3rd to 5th columns in the output. It tells in milliseconds the time it took to travel from origin to destination and then back again to origin. This one is also good to measure your network connection speed.

Running traceroute macos terminal is a nice and simple command utility to use. Hope this one is useful for anyone reading. Contact me if you have any questions.

See my inspirational T-Shirts and coffee mugs designs. I designed them all. Below are some examples. Let me know what you think.

Reload Config Apache httpd Without Restarting Apache in Linux

I was not sure when a client asked me “How do I gracefully restart Apache on my Linux server?” This prompt me to brew another coffee at home and then find how to reload Apache httpd config without restarting Apache server.

There are several methods for this depending on your Linux version:

apachectl
systemctl
service (older Linux distros)

Using apachectl to reload Apache

If you like to run a config test before reloading the config settings. You can do this with apachectl command:

apachectl configtest

and if everything is OK you can reload Apache httpd config next:

apachectl -k graceful

Using systemctl to reload Apache

This works for Linux distros running systemd. Syntax is easy:(you may need sudo in front of the command)

systemctl reload httpd
or
systemctl reload apache2

Using service or /etc/init.d to reload Apache httpd

You can also reload Apache in older Linux distros using System V init. Try these commands: (again you may need sudo in front of the command)

service httpd graceful
or
/etc/init.d/httpd graceful
or
/etc/init.d/apache2 reload (for Debian family)

Hope this is helpful. Contact me if you have any questions. Also, visit my shop where I feature cool T-shirts and coffee mugs I designed.

Here are some examples from my T-shirt and coffee mugs shop. Let me know what you think. Thanks.