Showing posts with label Notes on Linux. Show all posts
Showing posts with label Notes on Linux. Show all posts

Friday, February 22, 2019

Creating Self-Signed Certificates for the Apache Web Server

Use the OpenSSL package.  Issue the following commands in the Linux terminal:

# openssl req -new > ca.csr

# openssl rsa -in privkey.pem -out ca.key

# openssl x509 -in ca.csr -out ca.crt -req -signkey ca.key -days 720

These commands creates the SSL certificates good for 720 days with the files ca.csr, ca.crt, and ca.key.  Copy these files to the SSL directory of your Apache web server.  In my Linux system, this is located in /etc/apache2/ssl

# cp ca.* /etc/apache2/ssl

Then, restart the Apache webserver for the new certificates to take effect.

# service apache2 restart

Thursday, February 21, 2019

Mounting Remote SSH Filesystem

This is how to mount remote SSH (Secure Sockets Host) filesystem on your local directory (e.g., /home/clemrasul/remoteserv) on Linux.  Mounting remote directories in this way allows you to do server side programming with ease since source code can be edited using your favorite GUI text editor.  The text editor need not have the feature of being able to log on to an SSH server.  Here are the steps:

Step 1:  Install the sshfs software

On Ubuntu, this is done using the command apt-get.

# apt-get install sshfs


Step 2:  Place it in the Linux module and give permissions

# modprobe fuse
# adduser clemrasul fuse
# chown root:fuse /dev/fuse
# chmod +x /dev/fuse

This assumes a username of "clemrasul" that is added to the "fuse" group.


Step 3:  Create the directory where the remove SSH filesystem will be mounted

# cd /home/clemrasul
# mkdir ~/remoteserv

This assumes a remove directory name of "remoteserv".


Step 4:  Mount the remote SSH directory as follows:

# sshfs {fully qualified SSH username}:{default directory}  {local directory mount point}

Example:

# sshfs clemrasul@taocoven.com:/home/clemrasul/html ~/remoteserv

You will be prompted by the remote SSH server for password.  Once authenticated, the remote directory can be seen in the local directory as:

# cd /home/clemrasul/remoteserv/





Wednesday, September 16, 2015

How to extract the monthly report of an Apache log file

To extract the monthly report of an Apache log file, use the Linux sed command.  For example, to get the logs from July 1, 2015 to July 31, 2015, issue the command:

# sed -n '/1\/Jul\/2015/,/31\/Jul\/2015/ p' /opt/lamp/logs/access.log > Jul2015_log


Saturday, June 29, 2013

Disabling Services at Boot

Assuming you want to disable "squid" at boot, issue the command:

# update-rc.d -f squid remove


Sunday, May 19, 2013

How to burn iso image to USB

Assuming that your iso image file is located in "/home/clemrasul/linux.iso" and your USB is in "/dev/sdb", the Linux command to burn the image is:

#dd if=/home/clemrasul/linux.iso of=/dev/sdb

This command comes built-in in Linux. 

Thursday, August 9, 2012

How to execute a program at regular intervals in Ubuntu

Automatically executing a program at regular intervals in Ubuntu is undertaken using the Linux's/Unix's cron command. Here are the steps:

Step 1: Create the crontab file using an editor. For example:

# joe mycrontabfile.txt

Step 2: Enter the instructions for cron to follow. For example:

0 14 15,28 * * root /etc/firewall/firewall.sh

The instruction format is:

minute hour day month weekday user command

The values for minute is 0-59, hour is 0-23, day is 0-31, month is 0-12, weekday is 0-11. The asterisk character (*) is a wildcard and a comma (,) is a separator.

The above example means execute the program firewall.sh in the directory /etc/firewall with user root at 2pm on the 15th and 28th day of the month.


Step 3: Load the crontab file using the crontab command:

# crontab mycrontabfile.txt

Autoexecute a program in Ubuntu at Boot

Assuming you have a script file named "firewall.sh", to automatically execute the file at boot time in Ubuntu, issue the following commands:

# mv firewall.sh /etc/init.d/
# chmod +x /etc/init.d/firewall.sh
# update-rc.d /etc/init.d/firewall.sh defaults


To remove the autoexecute command, type:

# update-rc.d -f /etc/init.d/firewall.sh remove


Friday, July 1, 2011

Setting the Network Card to Static IP on Ubuntu

Edit the /etc/network/interaces file to:

auto eth1
iface eth1 inet static
address 10.10.10.2
netmask 255.255.255.0
gateway 10.10.10.1
dns-nameservers 10.10.10.250 10.10.10.251

Saturday, May 28, 2011

Installing Windows Fonts on Ubuntu Linux

There are three (3) ways to install Windows fonts on Ubuntu Linux. I have tested the following procedure under Ubuntu 10.10 Linux distribution but my guess is it should also work on other Linux distributions as well.

Way No. 1

(1) Access the Linux terminal by accessing the menu, Applications->Accessories->Terminal
(2) On the terminal, you have to be user "root" to install the package. To become "root", issue the command:

$ sudo su

This will prompt you for your password. Type in your password. If you are "root", the prompt should change from $ to #.

(3) To download and install the Windows fonts, type the command:

# apt-get install ttf-mscorefonts-installer

(4) To load the fonts, type the command:

# fc-cache -f -v


I am assuming that your computer is connected to the Internet and therefore by issuing the above-mentioned commands, installation of the fonts becomes trivial. As far as I know, you can also use the "Ubuntu Software Center" (click Applications->Ubuntu Software Center) and look for the MS True Type Fonts package.

If you are curious as to where the fonts are located, Ubuntu Linux copies the fonts to the directory "/usr/share/fonts". This directory is only accessible to the "root" user.


Way No. 2

In way 2, we will be installing fonts by manually copying the Windows fonts files and pasting it in the Ubuntu Linux directory.

(1) Copy the Windows fonts in your computer and place it in a transferable media such as a USB stick or CD.
(2) On the Ubuntu Linux computer, access the default home directory by going to "Places->Home Folder". On the home folder, check the "Show Hidden Files" on the "View" menu.
(3) Create the folder ".fonts". Yes, the folder got a dot before the word fonts. On Linux, folders with beginning dots means hidden folders.
(4) Copy the Windows fonts to the ".fonts" folder.
(5) Load the fonts by issuing the command:

$ fc-cache -f -v

As you can see, you don't need to be a "root" user to do this procedure. The fonts however will only be applied to the current user but not system wide unlike Way 1 procedure.


Way No. 3

In way 3, the procedure involves making the fonts available system-wide.

(1) On the terminal, become "root" by issuing the command:

$ sudo su

(2) Access the file manager in root mode by issuing the command:

# nautilus&

The file manager is called nautilus. The & makes the program independent of the terminal where it is run.

(3) Since you are already on the graphical file manager as "root", copy the Windows fonts to the Ubuntu Linux directory "/usr/share/fonts". I suggest creating a separate folder under this like "msttcorefonts".

(4) Load the fonts by issuing the command in the terminal:

# fc-cache -f -v


Other fonts can also be installed on Linux by following way 2 and 3 procedure above.

By the way, if you are concerned about licensing, the Microsoft Core fonts I have mentioned above can be redistributed freely as depicted in its license terms.

Friday, October 2, 2009

What is omserv running on port 764?

There is not much information on omserv running on port 764. By doing trial and error and using the lsof command, I found that omserv is actually nfslock. If you want to turn off this service (I surely do, since I don't know and use this service), issue the command:

chkconfig --levels 2345 nfslock off

This will remove the autoexecute of the nfslock. Afterwards, issue the command to stop the process:

/etc/rc.d/init.d/nfslock stop

To verify if you have stopped the service, type the command:

nmap localhost

Friday, May 1, 2009

What is port 111 on my CentOS box?

Port 111 on my CentOS 5.2 box is the "portmap" service. You can turn this off by issuing the following command:

#/etc/rc.d/init.d/portmap stop

By default, this is turned on my machine. So upon reboot of your machine, expect that is again turned on. If you want to set the default execution to off, issue the command:

#chkconfig --levels 2345 portmap off

Thursday, March 5, 2009

What process is running on the port?

Have you wondered what process is running on the port of your Linux box? The command to know the process that is running on the port is:

#lsof

This command comes handy with the #nmap program that identifies what ports are open. The command however tries to list all open files and therefore expect a long list to run through your screen. If you just want to investigate a particular port say port 898, use #lsof with grep:

#lsof | grep 898

This will list the open files with the particular port 898.

Knowing What Ports Are Open on Linux?

On Linux, it is easy to know what ports are open. You just need to use the program "nmap". If you don't have it on your system, download and install it using the command:

#apt-get install nmap

on your Ubuntu or using the yum for Fedora/RedHat/CentOS as follows:

#yum install nmap


Once installed, issue the command:

#nmap localhost

to know which ports are open in your computer.

Friday, December 19, 2008

Raw Printing in Linux

Raw printing in Linux is achieved by issuing the command and piping the result to /dev/lp0. For example:

# ls -l > /dev/lp0

Raw printing is useful if you want to take advantage of fast printing using the default fonts of the printer. More often, this is useful if you will be printing under a dot matrix printer.

Furthermore, you can also issue printer codes to the printer to make condensed printing as follows:

# echo -ne '\033\017' >> /dev/lp0

The printer code "\033\017" is an octal equivalent for condensed printing under an Epson-like dot matrix printers. Commonly, the following codes may also be used:

\033\115 for elite and \033\120 for pica

If you are using a different dot matrix printer, the printer codes are found in your printer manual.

Firewall Script

The following is a sample firewall script on Linux. It also acts as a network address translation (NAT) script that masquerades the IP addresses of the local area network. The script assumes that the local area network is in the 192.168.0.0 network class. Here it is:
# Load Modules
modprobe ip_conntrack
modprobe ip_conntrack_ftp

echo 1 > /proc/sys/net/ipv4/ip_forward

# Flush rules
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X

# Default Deny Policy
iptables -P INPUT DENY
iptables -P OUTPUT DENY
iptables -P FORWARD DENY

# Perform NAT
iptables -t nat -A POSTROUTING -s 192.168.0.0/255.255.255.0 -d 0.0.0.0/0.0.0.0 -j MASQUERADE

Thursday, December 18, 2008

Removing Comment Lines and Spaces in a File

How to remove comment lines and spaces on a configuration file in Linux?

To remove comment lines under Linux, issue the following command:

# sed -e '/^#/d' -e '/^$/d' < squid.conf > newsquid.conf

Then, go can backup the original squid.conf file by copying it to say squidconf.bak:

# cp squid.conf squidconf.bak

And finally copying the new squid file to replace the original file as:

# cp newsquid.conf squid.conf