How to edit default python version for a linux user?

Edit the bash profile and add an alias using the following code

$ nano ~/.bashrc

Put the following line of code in .bashrc file and alter the python3.6 path as per your new installation

alias python='/usr/local/bin/python3.6'

Use CTRL x to exit and save
After that you need to reload the source, so use the following command and you are good to go.

$ source ~/.bashrc

Windows v/s Linux. What’s your choice?

Hi Everyone.

Today we are going to talk about the two operating systems. Windows and Linux. Both of them have their own pros and cons.

Offcourse Windows have its monopoly with 88% plus market shares. Although slowly but Linux has started getting attention and getting more popular day by day.

Windows has dominated the market because it is way simpler to operate than any other operating system.

In this article, we will be focusing on understanding the two operating systems and their pros and cons.

So, let’s begin.

What is Windows operating system?

Windows is a series of operating systems, Each operating system comes with a graphical user interface (GUI) with a desktop which allows a user to view all files, videos etc. The first version of Windows OS was released in 1985 which was a simple GUI, an extension of the existing disk operating system (MS-DOS). windows OS comes with almost all company who made PC’s or laptops. Latest Windows OS version is Windows 10 which is currently ruling the market.

What is the Linux operating system?

Based on UNIX Linux is an open source operating system, created in 1991. Users can modify the existing code and create distributions from it as it is an open source operating system. Linux operating system also comes with a graphical user interface (GUI) with some necessary software’s which are used on a daily basis. Linux is mostly used as a server – as most of the web pages over the internet are generated from Linux servers and also used in desktop computers, mobile devices, gaming consoles, digital storing devices, eBook readers, cameras, video recorders have Linux running.

Comparison:

USES:

Linux is used by corporate, scientific, and academic organizations of every size. It’s used to power the development machines and servers at Google, Facebook, Twitter, NASA, and the New York Stock Exchange, just to name a few. On the desktop, it is used by technically proficient users who prioritize system security and reliability, and by enthusiasts who want to learn more about computers and how they work. Microsoft Windows is usually the operating system of choice for gamers, novice users, and business users who rely on Microsoft software. Many Windows users are thrilled with the changes that Microsoft has introduced with Windows 10, so if you’ve never used it, now is a great time to try it out.

SECURITY:

Linux is a highly secure operating system. Although attack vectors are still discovered, its source code is open and available for any user to review, which makes it easier to identify and repair vulnerabilities. Microsoft has made great security improvements over the years. But as the operating system with the largest user base, especially among novice computer users, it is the primary target for malicious coders. As a result, of all major operating systems, Microsoft Windows is the most likely to be the victim of viruses and malware.

USABILITY:

GNU/Linux operating systems have a steeper learning curve for the average user. They frequently require a deeper understanding of the underlying system to perform day-to-day functions. Additionally, troubleshooting technical issues can be a more intimidating and complicated process than on Window. Windows is one of the easiest desktop operating systems to use. One of its primary design characteristics is user-friendliness and simplicity of basic system tasks. Its ease lack of difficulty is considered positive by users who want their system to just work. However, more proficient users may be frustrated by the oversimplification of system tasks at the expense of fine-grained control over the system itself.

Conclusion:

So, ultimately it depends on the user.

If your use is just of a normal system which is dammed easy to use, go with Windows 10.

But if you are more of a geek, and would love to customize the system as per your needs, go with LINUX.

depends if i have to watch youtube or code

I had shifted to linux for 2-3 months but could not continue because windows have more gui software than any other known operating system. I like to keep things handy to me all the time, so windows.

I still encounter linux everyday because of ssh and servers

– Harshvardhan Malpani (tutes.in: Admin)

OK! everyone this is it for today. See you soon.

Thank You.

How to repair a MySQL database?

Hello! Good to see you.

This is going to be a very important article because we are about to discuss  “How to repair a MySQL database?”

Why repair MySQL Database?

Databases can become corrupted for any number of reasons, from software defects to hardware issues.

If this occurs, you can try to repair the database. Wondering how to do it? Just follow this article.

REPAIRING MYSQL DATABASES:

Let’s see how to repair MySQL database through Linux and Windows command line.

Repair MySQL Database through Windows command line.

 

  • Log in to your Windows VPS using Remote Desktop.
  • Go to Start and locate the Command Prompt. Right-click Command Prompt and select Run as Administrator option.
  • At windows command prompt navigate to MySQL bin directory as follows.
    cd C:\Program Files\MySQL\MySQL Server 5.5\bin  //  Replace your MySQL bin directory path here.
  • Run the following command to start the MySQL prompt.
    mysql -u root -p
  • Enter MySQL root password when you are being asked.
  • You will see MySQL prompt appearing. Now, to display all databases, type following command at MySQL prompt:
    show databases;
  • Enter the following command to repair MySQL database.
    mysqlcheck -r [database] // Replace database name with your database name.

Repair MySQL Database through Linux Terminal.

 

  • Login to your Linux VPS using Secure Shell (SSH) and connect to MySQL from the command line.
    mysql -uUsername -p // Replace Username with your username.
  • Enter MySQL user password and hit Enter. You will see MySQL prompt appearing. Now, in order to display all databases, type following command at MySQL prompt.
    show databases;
  • mysqlcheck enables you to check databases without stopping the entire MySQL service. -r argument is used to repair the corrupted tables. mysqlcheck utility efficiently works on both MyISAM and InnoDB database engines. Enter the following command to repair MySQL database.
    mysqlcheck -r [database] // Replace database name with your database name.

 

So, we covered this issue for both Windows and Linux.

Lastly please check our other articles on various topics, that we tried to address.

Thank You.

Linux commands for SSH

  1. tar– to create archive files(.zip, .tar)

Syntax:
tar [options] [archive-file] [file or directory to be archived]

Options:
-c : Creates Archive
-x : Extract the archive
-f : creates archive with given filename
-t : displays or lists files in archived file
-u : archives and adds to an existing archive file
-v : Displays Verbose Information
-A : Concatenates the archive files
-z : zip, tells tar command that create tar file using gzip
-j : filter archive tar file using tbzip
-W : Verify a archive file
-r : update or add file or directory in already existed .tar file

2. curl – Transfers data from or to a server, using one of the protocols: HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE.

Syntax:
curl [options] [URL…]

3. service– The service command is used to run a System V init script. Usually all system V init scripts are stored in /etc/init.d directory and service command can be used to start, stop, and restart the daemons and other services under Linux.

Syntax:
service SCRIPT-Name COMMAND
The COMMAND can be at least start, stop, status, and restart.

4. netstat– The netstat command is used to display very detailed information about how your computer is communicating with other computers or network devices.

5. wget– Wget is the non-interactive network downloader which is used to download files from the server even when the user has not logged on the system and it can work in background without hindering the current process.

Syntax:
wget [option] [URL]

6. grep– The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern.

Syntax:
grep [options] pattern [files]

Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.

7. ls – list directory contents
Syntax:
ls [OPTION]… [FILE]…

ls -l list with long format, show permissions
ls -la list long format including hidden files

8. cat – Concatenate and print the content of files.

Syntax:
cat [Options] [File]…

9. nano– GNU nano is a text editor for Unix-like computing systems or operating environments using a command line interface.

10. vi – vi is a screen-oriented text editor originally created for the Unix operating system.

11. cp – cp stands for copy. This command is used to copy files or group of files or directory.

Syntax:
cp [OPTION] Source Destination
cp [OPTION] Source Directory
cp [OPTION] Source-1 Source-2 Source-3 Source-n Directory

First and second syntax is used to copy Source file to Destination file or Directory.
Third syntax is used to copy multiple Sources(files) to Directory.

12. mv– mv stands for move. mv is used to move one or more files or directories from one place to another in file system

Syntax:
mv [Option] source destination

13. sudo– sudo (“superuser do”, or “switch user do”) allows a user with proper permissions to execute a command as another user, such as the superuser.

14. rm -rm stands for remove here. rm command is used to remove objects such as files, directories, symbolic links and so on from the file system
Syntax:
rm [OPTION]… FILE…

15. mkdir– make directories
Syntax-
mkdir [OPTION]… DIRECTORY…

16. ln -The ln command is a standard Unix command utility used to create a hard link or a symbolic link (symlink) to an existing file. The use of a hard link allows multiple filenames to be associated with the same file since a hard link points to the inode of a given file, the data of which is stored on disk.
Syntax:
ln [OPTIONS] TARGET… LINK|DIRECTORY

RPM repo not found connection errors on Centos Redhat duplicate problems

yum -y update command failing

Command line will show messages like

xxx is outdated and v abc will be installed
but at the end it shows duplicate binary, please remove duplicate first.

Process

Backup first
Integrity Check
Find Problems
Identify duplicates
Clean duplicates
re build conf cache
update command
remove backup file .prev if successfully solved

\cp -r /var/lib/rpm /var/lib/rpm.prev
yum-complete-transaction
package-cleanup --problems
package-cleanup --dupes
package-cleanup --cleandupes
yum clean all
rpm --rebuilddb
yum update
# if all went OK run 'rm -rf /var/lib/rpm.prev'

Other possible solution

1. Update DNS to google dns 8.8.8.8 and 8.8.4.4 or freenom dns 80.80.80.80 and 80.80.81.81

system-config-network

2. Restart internet while maintaining SSH session (you wont be logged out)

/etc/init.d/network restart

Linux – Rescue disk how to reset root password and unblock yourself if locked out

Centos as test server

Current situation – you are locked out, cant use WHM or SSH or anything else to login.
You may or may not remember the password. In any case you can reproduce the following steps to unblock yourself.

1. Use any other linux OS cd which can run live. I prefer FINNIX iso for such cases
2. Mount your main disk.

mount /dev/vda1 /mnt

3. Reset password if needed to

chroot /mnt passwd

4. Enter new password for root and confirm
5. Reboot and done.

In case you have been locked out due to WHM cpanel:
1. Use any other linux OS cd which can run live. I prefer FINNIX iso for such cases
2. Mount your main disk.

mount /dev/vda1 /mnt

3. Stop cphulk service for brute force protection

chroot /mnt /usr/local/cpanel/etc/init/stopcphulkd
chroot /mnt /usr/local/cpanel/bin/cphulk_pam_ctl --disable

4. Disable the lock for cphulk so that it does not start automatically after restart

chroot /mnt rm /var/cpanel/hulkd/enabled

5. Reboot and done

METHOD 2 – in case you are blocked at firewall level

In case you have been locked out due to WHM cpanel and just want to whitelist yourself:
1. Use any other linux OS cd which can run live. I prefer FINNIX iso for such cases
2. Mount your main disk.

mount /dev/vda1 /mnt

3. Stop cphulk service for brute force protection

chroot /mnt /usr/local/cpanel/etc/init/stopcphulkd
chroot /mnt /usr/local/cpanel/bin/cphulk_pam_ctl --disable

4. Disable the lock for cphulk so that it does not start automatically after restart

chroot /mnt /scripts/cphulkdwhitelist XXX.82.6.156

5. Remove yourself from firwall

chroot /mnt whmapi1 flush_cphulk_login_history_for_ips ip=XXX.82.6.156

6. Reboot and done


Remove lockouts
If the cPHulk service locks you out of your cPanel account, the /scripts2/doautofixer?autofix=disable_cphulkd script in WHM can disable cPHulk and allow you to log in.

For example, log in to WHM and navigate to https://www.example.com:2087/scripts2/doautofixer?autofix=disable_cphulkd, where www.example.com represents your server’s hostname.

If you enabled the Block IP addresses at the firewall level if they trigger brute force protection or the Block IP addresses at the firewall level if they trigger a one-day block options in WHM’s cPHulk Brute Force Protection interface (WHM >> Home >> Security Center >> cPHulk Brute Force Protection), remove the iptables rule that the system created. To do this, run the following command:

iptables -F cphulk && mysql -e "Delete from cphulkd.login_track;"

Linux Bash – How to change all filenames to uppercase leaving the file extension unchanged

use this simple code in bash shell. The following code will change all xxx.jpg files to XXX.jpg in any particular working directory.

for i in *.jpg; do 
ext=${i##*.}; 
name=$(basename "$i" ".$ext" | tr '[a-z]' '[A-Z]').$ext; 
if [ "$i" != "$name" ] 
then 
mv $i $name;
fi
done;

Compressing images directly on web server – Better Pagespeed tips

for png, install on centos using command

yum install optipng

for a single image

optipng -o5 filename.png

move to folder in which pngs are stored and use the following command:

for i in *.png; do optipng -o7 -strip all  -quiet "$i"; done

this will overwrite all pngs, o7 is switch for number of tries. o5 will be less time consuming though. -quiet makes it muted, outputs nothing.
-strip all will try to remove all meta data.
you can use -preserve to preserve the modification date.
also try -keep, if you want to save backup of each file