I had a problem with apache displaying ? instead of ' or " and other symbols.
For example: A sentence ?like this? wouldn?t display correctly.
Solution:
in your httpd.conf file, I changed the AddDefaultCharset to:
AddDefaultCharset iso-8859-1
It was on UTF-8, newer installs may have this incorrect.
Friday, June 24, 2011
Delete all lines containing a pattern
Category:
Vim
— SkyHi @ Friday, June 24, 2011
The ex command g is very useful for acting on lines that match a pattern. You can use it with the d command, to delete all lines that contain a particular pattern, or all lines that do not contain a pattern.
For example, to delete all lines containing "profile" (the first command is optional; it shows the lines that the second command will delete):
:g/profile
:g/profile/d
More complex patterns can be used, such as deleting all lines that are empty or that contain only whitespace:
:g/^\s*$/d
To delete all lines that do not contain a pattern, use g!, like this command to delete all lines that are not comment lines in a Vim script:
:g!/^\s*"/d
Note that g! is equivalent to v, so you could also do the above with:
:v/^\s*"/d
The next example shows use of \| ("or") to delete all lines except those that contain "error" or "warn" or "fail" (:help pattern):
:v/error\|warn\|fail/d
REFERENCES
http://vim.wikia.com/wiki/Delete_all_lines_containing_a_pattern
For example, to delete all lines containing "profile" (the first command is optional; it shows the lines that the second command will delete):
:g/profile
:g/profile/d
More complex patterns can be used, such as deleting all lines that are empty or that contain only whitespace:
:g/^\s*$/d
To delete all lines that do not contain a pattern, use g!, like this command to delete all lines that are not comment lines in a Vim script:
:g!/^\s*"/d
Note that g! is equivalent to v, so you could also do the above with:
:v/^\s*"/d
The next example shows use of \| ("or") to delete all lines except those that contain "error" or "warn" or "fail" (:help pattern):
:v/error\|warn\|fail/d
REFERENCES
http://vim.wikia.com/wiki/Delete_all_lines_containing_a_pattern
How Fast Can You Type? Develop a Tiny Utility in Bash to Find Out
If you spend most of your time typing on your keyboard (and I hope you don’t use that mouse very frequently, if you care for your wrists, that is), getting up to speed and practicing to become a better and faster typist is well worth the time and effort. And measuring something is the first step to improve it.
There are tons of applications which test your typing abilities and help you improve it, but wouldn’t it be nice to have a basic idea about your typing performance using nothing but good old Bash? After all, this is about DIY (Do It Yourself) approach and having fun; two notions that Linux Journal readers know very well.
The idea is actually very simple: Measuring the typing speed means basically measuring how many words you typed in a given amount of time. One of the most popular units used is wpm (words per minute). Maybe not very accurate and scientific, but we’re aiming for a ballpark figure here so some approximate measure will be fine for our purpose. Based on this information we can write the formula as:
If you save the above shell script as speed.sh and make it executable, you are ready to measure your typing speed. Oh, I forgot one thing, that is a piece of text to type. It is always good to have some text ready so that you’ll know what you type. In this case I prefer the first few lines of the Usenet message of Linus Torvalds in which he announced the birth of Linux:
The tiny utility above helped me to have a rough idea about my typing speed. Certainly it lacks some important features. It would be nice if:
Happy hacking and typing.
REFERENCES
http://www.linuxjournal.com/content/how-fast-can-you-type-develop-tiny-utility-bash-find-out
There are tons of applications which test your typing abilities and help you improve it, but wouldn’t it be nice to have a basic idea about your typing performance using nothing but good old Bash? After all, this is about DIY (Do It Yourself) approach and having fun; two notions that Linux Journal readers know very well.
The idea is actually very simple: Measuring the typing speed means basically measuring how many words you typed in a given amount of time. One of the most popular units used is wpm (words per minute). Maybe not very accurate and scientific, but we’re aiming for a ballpark figure here so some approximate measure will be fine for our purpose. Based on this information we can write the formula as:
typing_speed_in_wpm = num_words / ( (end_time - start_time) / 60 )Now that we have our theoretical framework set up, it is time to build the practical computational part of the project. Before diving into code, let’s break down the above formula into pieces and see which GNU/Linux utilities can help us achieve various tasks:
- date: This is our well-known utility and if you use it with the %s format specifier it returns the “seconds since 1970-01-01 00:00:00 UTC”. So if you run date +%s once at the beginning of your typing session and once at the end of it, you’ll have the end_time and start_time.
- wc: This is yet another well-known utility that can give you the number of words in a file if invoked with -w option. And remember, in GNU/Linux almost everything is a file, including your input from the keyboard.
- cat: Officially it concatenates files and print them on the standard output. Practically it can grab your input from the keyboard and via a pipe send that to the wc. In other words all we need to do to count the number of words we just typed is to issue the following command:
cat | wc -w
- bc: Officially it is an arbitrary precision calculator language. Practically it is a very handy utility if you want to do calculations within the command line. But you have to be careful and read its manual page. Why? Well, if you try these:
$ echo 1 + 1 | bc 2everything seems fine but if you try the following:
$ echo 1 / 2 | bc 0That’s not what you’d expect from a computer. Why doesn’t it return the correct answer, that is 0.5? According to its manual page “scale defines how some operations use digits after the decimal point. The default value of scale is 0.” Apparently it is not a very sensible default for our division operations which we’ll use later. The solution then is to tell bc what scale to use before doing the operation, e.g.:
$ echo “scale=2; 1 / 2” | bc 0.50That’s much better. We have all the components in place and now it is time to glue them together using our favorite application development environment, Bash:
#!/bin/sh # speed.sh: a very tiny utility to measure typing speed. prompt="Start typing a piece of text. Press Ctrl-d twice to finish." echo "\n$prompt \n" start_time=`date +%s` words=`cat|wc -w` end_time=`date +%s` speed=`echo "scale=2; $words / ( ( $end_time - $start_time ) / 60 )" | bc` echo "\n\nYou have a typing speed of $speed words per minute."
If you save the above shell script as speed.sh and make it executable, you are ready to measure your typing speed. Oh, I forgot one thing, that is a piece of text to type. It is always good to have some text ready so that you’ll know what you type. In this case I prefer the first few lines of the Usenet message of Linus Torvalds in which he announced the birth of Linux:
$ ./speed.shStart typing a piece of text. Press Ctrl-d twice to finish.
Hello everybody out there using minix - I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. This has been brewing since april, and is starting to get ready. You have a typing speed of 43.33 words per minute.Well, 43.33 words per minute is not a world record for sure (and I definitely had better scores, believe me!). According to the relevant Wikipedia article, “as of 2005, writer Barbara Blackburn was the fastest English language typist in the world, according to The Guiness Book of World Records. Using the Dvorak Simplified Keyboard, she has maintained 150 words per minute (wpm) for 50 minutes, and 170 wpm for shorter periods. She has been clocked at a peak speed of 212 wpm.” I don’t know, maybe it is time to switch to the Dvorak simplified keyboard but I have my doubts.
The tiny utility above helped me to have a rough idea about my typing speed. Certainly it lacks some important features. It would be nice if:
- It included various texts and showed them in a random order so that the average performance of different typing sessions can be calculated. A single measurement is hardly a reliable indicator when it comes to this kind of benchmarking.
- It had the option of getting sample texts from files.
- It took into account the number of errors made by the typist. This calls for a small function that can compare the sample text and the input of the typist. It does not mean much if your performance is 1000 wpm but 90% of it includes terrible errors, typos, etc.
Happy hacking and typing.
REFERENCES
http://www.linuxjournal.com/content/how-fast-can-you-type-develop-tiny-utility-bash-find-out
Wednesday, June 22, 2011
How do I Compare two files under Linux or UNIX?
Category:
Compare_files
— SkyHi @ Wednesday, June 22, 2011
You need to use diff command to display line-by-line difference between two files. The general syntax of diff command as follows:
diff FILE1 FILE2Where,
FILE1 FILE2: Diff command will examine both file1 and file2 and tells you what changes need to be made for file1 and file2 to match. Please note that diff command point to which lines need be:- Added (a)
- Deleted (d)
- Changed (c)
- Further lines in file1 identified with a less than () symbol and lines in file2 with a grater than (>) symbol.
Examplesdiff file1.txt file2.txtOutput:8c8,9
URL: www.nixcraft.in
> Email: support@nixcraft.in
The contents of both files:$ cat file1.txtOutput:Welcome to nixCraft!
If undeliverd return to nixCraft
#404, DC bay area, 2nd phase,
Pune.
Ph: 555-11112223
URL: www.nixcraft.com
$ cat file2.txtOutput:Welcome to nixCraft!
If undeliverd return to nixCraft
#404, DC bay area, 2nd phase,
Pune.
Ph: 555-11112223
URL: www.nixcraft.in
Email: support@nixcraft.in
Side-by-side merge of file differences
You can get a clear-cut visual difference between two text files using the command sdiff:$ sdiff file1.txt file2.txtOutput:Welcome to nixCraft! Welcome to nixCraft!
If undeliverd return to nixCraft If undeliverd return to nixCraft
#404, DC bay area, 2nd phase, #404, DC bay area, 2nd phase,
Pune. Pune.
Ph: 555-11112223 Ph: 555-11112223
URL: www.nixcraft.com | URL: www.nixcraft.in
> Email: support@nixcraft.in
REFERENCES
diff FILE1 FILE2
FILE1 FILE2: Diff command will examine both file1 and file2 and tells you what changes need to be made for file1 and file2 to match. Please note that diff command point to which lines need be:
You can get a clear-cut visual difference between two text files using the command sdiff:
Tuesday, June 21, 2011
Install fail2ban 0.84 on Centos 5.5
Category:
fail2ban
— SkyHi @ Tuesday, June 21, 2011
Fail2ban is an intrusion prevention framework which scans the log files on your system (such as: var/log/secure) and spots repeated password failures.
Too many failures, and it will update your firewall to drop all traffic from the offending IP address. Pretty handy, and enough to stop the casual hacker with a dictionary attack.
Fail2ban is very flexible and can be configured to work with any service that writes to a logfile, but here’s the basics to get you up and protected in a few minutes.
1. Get the files
cd to /tmp for a nice place for them to land, then
2. Extract them
3. Head to the new directory and install
then (you need to have python installed)…
All installed ok?
4. Get it starting up automatically
5. Config
You’ll need to turn some stuff on, and fiddle with settings to your liking in:
/etc/fail2ban/jail.conf
If you’re enabling SSH-iptables, then the path for SSH monitoring needs to be changed to /var/log/secure
You can determine the services being monitored, number of retries a user is allowed, as well as the ban time in this settings file.
Once you’re configured, start the service with:
You can test the rules per service using:
The defaults should work correctly for SSH but if they don't, check out this article for more options.
NOTE: fail2Ban 0.8.4 doesn't ban VSFTPD failures
Once I realized that fail2ban was configured to ignore failed logins from my LAN IP's, I did manage to get banned. The following settings worked for me:
/etc/vsftpd/vsftpd.conf:
/etc/fail2ban/jail.conf:
I left default settings for IP tables and for /etc/fail2ban/filter.d/vsftpd.conf
REFERENCES
http://www.md3v.com/install-fail2ban-on-centos-5-5
http://willgrant.org/install-fail2ban-on-centos-5-6/
http://pbxinaflash.com/forum/showthread.php?t=9847
Too many failures, and it will update your firewall to drop all traffic from the offending IP address. Pretty handy, and enough to stop the casual hacker with a dictionary attack.
Fail2ban is very flexible and can be configured to work with any service that writes to a logfile, but here’s the basics to get you up and protected in a few minutes.
1. Get the files
cd to /tmp for a nice place for them to land, then
wget http://sourceforge.net/projects/fail2ban/files/fail2ban-stable/fail2ban-0.8.4/fail2ban-0.8.4.tar.bz2/download
2. Extract them
tar -xf fail2ban-0.8.4.tar.bz2
3. Head to the new directory and install
cd fail2ban-0.8.4
then (you need to have python installed)…
python setup.py install
All installed ok?
4. Get it starting up automatically
cp files/redhat-initd /etc/init.d/fail2ban
chkconfig --add fail2ban
chkconfig fail2ban on
5. Config
You’ll need to turn some stuff on, and fiddle with settings to your liking in:
/etc/fail2ban/jail.conf
If you’re enabling SSH-iptables, then the path for SSH monitoring needs to be changed to /var/log/secure
You can determine the services being monitored, number of retries a user is allowed, as well as the ban time in this settings file.
Once you’re configured, start the service with:
service fail2ban start
6.
You can test the rules per service using:
fail2ban-regex /var/log/secure /etc/fail2ban/filter.d/sshd.conf
The defaults should work correctly for SSH but if they don't, check out this article for more options.
NOTE: fail2Ban 0.8.4 doesn't ban VSFTPD failures
Once I realized that fail2ban was configured to ignore failed logins from my LAN IP's, I did manage to get banned. The following settings worked for me:
/etc/vsftpd/vsftpd.conf:
Code: |
dual_log_enable=YES use_localtime=YES |
/etc/fail2ban/jail.conf:
Code: |
[vsftpd-iptables] enabled = true filter = vsftpd action = iptables[name=VSFTPD, port=ftp, protocol=tcp] sendmail-whois[name=VSFTPD, dest=root@localhost, sender=fail2ban@pbx.dyndns.org] logpath = /var/log/vsftpd.log maxretry = 3 bantime = 1800 |
I left default settings for IP tables and for /etc/fail2ban/filter.d/vsftpd.conf
REFERENCES
http://www.md3v.com/install-fail2ban-on-centos-5-5
http://willgrant.org/install-fail2ban-on-centos-5-6/
http://pbxinaflash.com/forum/showthread.php?t=9847
Migrate (move) SSL certificate from Windows to Linux
Category:
SSL,
Windows IIS
— SkyHi @ Tuesday, June 21, 2011
Often, people who are not familiar with hosting servers, to be enticed by sales agents to buy new SLL certificates, because \"It is not possible to be migrated from Windows to Linux\".
With this tutorial I will show you how to move existing SSL certificate from Windows to Linux server.
Here I have to say that this tutorial will work, only if the certificate was installed without this option checked: ”Mark this key as exportable. This will allow you to back up or transport your keys at a later time.” Check the screen-shoot bellow to see what I mean:
So, if this option was not checked during the certificate installation I am afraid that the only option is to ask the certificate issuer.
Well, I hope in your case this option was checked, so let’s continue with the SSL certificate migration.
First export the certificate from the Windows server. Depending on the server configuration you can export it from IIS:
Just if you are not aware:
Click Start Buton -> Run… – type: intemgr – then locate the domain, right click then Properties – Directory Security – Server Certificate
If you have Active Directory setup to export the certificate:
Again just in case you do not know how:
Click Start Buton -> Run… – type: mmc – then Open – Add/Remove Snap-in.. – click ‘Add’, choose certificates, choose computer account, then ‘Local computer’. Then expand ‘Certificatesc – ‘Personal’ -‘Certificated, locate the certificate and right click on it. Click ‘All task’ and ‘Export..’.
I presume you have successfully managed to export the SSL certificate pfx file.
Now move from the Windows to the Linux server the exported certificate and let’s do the magic, which is called: Extract SSL certificate and key from PFX file
REFERENCES
http://www.onlinehowto.net/migrate-move-ssl-certificate-from-windows-to-linux/1504
If you have landed on this tutorial and do not have PFX certificate file please visit: Migrate (move) SSL certificate from Windows to Linux.
The certificate extraction can be done with a tool called Open SSL that you may install from the Linux server repository, or take the source from here: OpenSSL. Also you can use the Windows version: OpenSSL for Windows.
Once you have it installed go to the folder where the PFX certificate is located and execute the following commands:
Probably from the comments, you guessed already what line what is doing, but I will explain these lines briefly:
The first line will export the private key from the windows certificate and since PFX key is always exported with a password, you will be prompted to enter one. So you must have it.
The second line will export certificate from the PFX file.
Again, you will need the PFX file password in order to remove it. In fact you can use the certificate with Apache server, but whenever it is restarted you will be prompted for a passphrase. If you choose this case, forget for automated Apache restarts and take in mind that you have to enter the pass after server restart. Like this one:
My advice is to remove the password from the SSL key. If someone manage to access it on the server, this will be you’re the least of your problems.
Well, that is it. Now you can rename the key and the certificate as per your needs and to use them.
I have another tutorial related to the matter is: Renew Windows SSL certificate when no key available.
REFERENCES
http://www.onlinehowto.net/extract-ssl-certificate-and-key-from-pfx-file/1505
http://www.opensourcetutor.com/2007/08/08/convert-iis-ssl-certificate-to-use-in-apache/
http://almamunbd.blogspot.com/2010/11/how-to-move-ssl-from-windows-to-linux.html
IIS: Export Private Key Option is Grayed When Exporting a Server Certificate
REFERENCES:
http://support.microsoft.com/kb/232154
http://www.eggheadcafe.com/microsoft/IIS/31331452/exporting-the-private-key--certificates.aspx
Solution for the above doesn't apply:
Yes, you would have to reissue the certificate if the private key
cannot be exported. Generate a new CSR on the Linux box that you want to
install the certificate to and follow these instructions to replace
(reissue) your certificate based on that new CSR ...
The agent is sending you to
https://search.thawte.com/support/ssl-digital-certificates/index?page=content&id=SO6285&actp=AGENT_REFERAL.
With this tutorial I will show you how to move existing SSL certificate from Windows to Linux server.
Here I have to say that this tutorial will work, only if the certificate was installed without this option checked: ”Mark this key as exportable. This will allow you to back up or transport your keys at a later time.” Check the screen-shoot bellow to see what I mean:
So, if this option was not checked during the certificate installation I am afraid that the only option is to ask the certificate issuer.
Well, I hope in your case this option was checked, so let’s continue with the SSL certificate migration.
First export the certificate from the Windows server. Depending on the server configuration you can export it from IIS:
Just if you are not aware:
Click Start Buton -> Run… – type: intemgr – then locate the domain, right click then Properties – Directory Security – Server Certificate
If you have Active Directory setup to export the certificate:
Again just in case you do not know how:
Click Start Buton -> Run… – type: mmc – then Open – Add/Remove Snap-in.. – click ‘Add’, choose certificates, choose computer account, then ‘Local computer’. Then expand ‘Certificatesc – ‘Personal’ -‘Certificated, locate the certificate and right click on it. Click ‘All task’ and ‘Export..’.
I presume you have successfully managed to export the SSL certificate pfx file.
Now move from the Windows to the Linux server the exported certificate and let’s do the magic, which is called: Extract SSL certificate and key from PFX file
More From onlinehowto
- Install SSL certificate in Google Chrome
- Install SSL certificate in Internet Explorer 7
- Setup proxy in Google Chrome in Linux Gnome
REFERENCES
http://www.onlinehowto.net/migrate-move-ssl-certificate-from-windows-to-linux/1504
Extract SSL certificate and key from PFX file
Anthony Gee | Apr 16, 2010 | Comments 3
In this tutorial I will show you how to extract SSL certificate and key from PFX file and also how to remove a password from a private SSL key.If you have landed on this tutorial and do not have PFX certificate file please visit: Migrate (move) SSL certificate from Windows to Linux.
The certificate extraction can be done with a tool called Open SSL that you may install from the Linux server repository, or take the source from here: OpenSSL. Also you can use the Windows version: OpenSSL for Windows.
Once you have it installed go to the folder where the PFX certificate is located and execute the following commands:
- # To export the private key from the pfx file:
- openssl pkcs12 -in win_cert.pfx -nocerts -out key.pem
- # To export the certificate from the pfx file:
- openssl pkcs12 -in win_cert.pfx -clcerts -nokeys -out cert.pem
- # And now remove the key password:
- openssl rsa -in key.pem -out key_with_no_pw.key
The first line will export the private key from the windows certificate and since PFX key is always exported with a password, you will be prompted to enter one. So you must have it.
The second line will export certificate from the PFX file.
Again, you will need the PFX file password in order to remove it. In fact you can use the certificate with Apache server, but whenever it is restarted you will be prompted for a passphrase. If you choose this case, forget for automated Apache restarts and take in mind that you have to enter the pass after server restart. Like this one:
- /etc/init.d/apache2 start
- Starting web server (apache2)…[Mon Apr 22 23:03:45 2010] [warn] module ssl_module is already loaded, skipping
- Apache/2.2.3 mod_ssl/2.2.3 (Pass Phrase Dialog)
- Some of your private key files are encrypted for security reasons.
- In order to read them you have to provide the pass phrases.
- Server 127.0.0.1:443 (RSA)
- Enter pass phrase:*******
- OK: Pass Phrase Dialog successful.
Well, that is it. Now you can rename the key and the certificate as per your needs and to use them.
I have another tutorial related to the matter is: Renew Windows SSL certificate when no key available.
REFERENCES
http://www.onlinehowto.net/extract-ssl-certificate-and-key-from-pfx-file/1505
http://www.opensourcetutor.com/2007/08/08/convert-iis-ssl-certificate-to-use-in-apache/
http://almamunbd.blogspot.com/2010/11/how-to-move-ssl-from-windows-to-linux.html
IIS: Export Private Key Option is Grayed When Exporting a Server Certificate
REFERENCES:
http://support.microsoft.com/kb/232154
http://www.eggheadcafe.com/microsoft/IIS/31331452/exporting-the-private-key--certificates.aspx
Solution for the above doesn't apply:
Yes, you would have to reissue the certificate if the private key
cannot be exported. Generate a new CSR on the Linux box that you want to
install the certificate to and follow these instructions to replace
(reissue) your certificate based on that new CSR ...
The agent is sending you to
https://search.thawte.com/support/ssl-digital-certificates/index?page=content&id=SO6285&actp=AGENT_REFERAL.
Sunday, June 19, 2011
boot Windows XP from usb flash
Category:
Windows XP
— SkyHi @ Sunday, June 19, 2011
1. download WinToFlash (http://wintoflash.com/home/en/)
2. select option 1 text mode to boot(Note: option 2 GUI is default, would get missing hal.dll error)
3. after xp has installed and reboot
4. select option 2 GUI to continue to install.
4. Finally, select option 2 GUI to finish.
NOTE: tried on HP 110 mini(http://h10025.www1.hp.com/ewfrf/wc/softwareCategory?os=228&lc=en&cc=ca&dlc=en&sw_lang=&product=3979292#N202), it works fine.
2. select option 1 text mode to boot(Note: option 2 GUI is default, would get missing hal.dll error)
3. after xp has installed and reboot
4. select option 2 GUI to continue to install.
4. Finally, select option 2 GUI to finish.
NOTE: tried on HP 110 mini(http://h10025.www1.hp.com/ewfrf/wc/softwareCategory?os=228&lc=en&cc=ca&dlc=en&sw_lang=&product=3979292#N202), it works fine.
Subscribe to:
Posts (Atom)