Wednesday, February 3, 2016

Using VI

Using VIM (originally VI)  Visual Improved Text Editor


VIM or VI is the de facto text editor for all Unix systems.

This post is for those who want to learn how to use VI.  I am not going to get into VI vs Emacs or any other religious wars such as Linux vs Windows etc.  The simple fact is that any Unix box you use will have VI installed so knowing at least the basics will help you in a pinch (or when your system is floundering you can rescue it.)

Start Here

Essential Commands (short quick ref for VIM)

ESC   - change to command mode. The following commands will then work:
:q!      - quit without saving
:wq    - write changes then quit
i         - insert mode (enter text)
dd      - delete one line
yy      - copy current line
p        - paste last copied /deleted line
R       - replace until ESC is hit
r         - replace one character
/text   - locate the string text search forward in the file (then n for next)

Other VIM Resources

Thursday, October 29, 2015

Fun things to do with telnet

Because it's almost useless, except for port probing...
Telnet is an old client server TCP/IP protocol that allows for clear text remote access to a shell. Because everything is sent in clear text it is really no longer used, instead we use ssh client and server.

(You can do this on any Linux box and if you must use windoze there is nothing I can do to stop you)
The protocol still exists and can be used for sh1ts and giggles:

Open a terminal and type the highlighted part:

NYAN Cat!
telnet nyancat.dakko.us

ASCII Star Wars (an IPV6 version is available too) (You can see the same thing via a web browser here http://www.asciimation.co.nz/)
telnet towel.blinkenlights.nl 

BOFH Excuse Engine, don't forget the 666,:
telnet towel.blinkenlights.nl 666



If you want to try some old BBS & MUDs  there are a few here http://www.telnet.org/htm/places.htm
and here http://www.telnetbbsguide.com/   or ask google.

Tuesday, April 22, 2014

Somebody attacking your ssh daemon??

sshd[5948]: Failed password for root from 116.10.191.220
sshd[5948]: Failed password for root from 116.10.191.220
sshd[5948]: Failed password for root from 116.10.191.220

You can stop this easily with iptables rules.  The following two rules limit connection attempts on port 22 to maximum 4 every 90 minutes, if you get more attempts they will be dropped.



iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent \
  --set
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent \
  --update --seconds 90 --hitcount 4 -j DROP

  1. First line: any NEW connections to port 22 over TCP use the recent module to keep track of the IP address; the -m recent --set takes care of this. 
  2. Second line: -m recent --update checks if the IP address of the incoming connection is in the recent list. The --seconds and --hitcount limit the match to within 90 seconds and 4 tries.
i.e.. Drop if: IP address previously in recent list AND IP address has tried to make a NEW connection within the last 90 minutes AND IP address has tried more than 4 times.

 Stops that nasty traffic!

ref: http://www.debian-administration.org/articles/187

Wednesday, April 18, 2012

tell SELinux to calm down & get out of the way

DO NOT DO THIS on an internet facing computer, this is only for crash and burn Linux boxen that you are testing in your lab and changing rapidly.

This applies to RedHat, Fedora or CentOS.  When you are in a test lab or even just trying different configurations for your server SELinux can get in your way. It may block what you are trying to do without notice or it may pop up several notices telling you that it is doing so. Either way it can be painful to test or change service configurations with it in full blown enforcing mode. So to make it less intrusive you may do the following (as root or sudo of course):
  1. Edit /etc/sysconfig/selinux with your favourite text editor
  2. You should see 
  3. Change the line SELINUX=enforcing to read
    SELINUX=permissive
  4. Save the file
  5. Reboot
That's it.  It will now log the information but not block your changes.  Of course once you are ready to go live, put it back!

To see the current status
CLI:  sestatus

By the way if you want to toggle it off and on temporarily:
CLI:  setenforce Permissive
or
CLI:  setenforce Enforcing

Friday, October 14, 2011


I am at heart a C programmer, this is sad.  One of the fathers of C hence Unix and so the grandfather of Linux has died.

DMR Denis M. Ritchie 1949-2011



Google+ post by Rob Pike
techcrunch.com

Tuesday, April 19, 2011

Free Bash shell

Sometimes you need to do things from another network off of your own box, having a free shell account elsewhere can help.  The lists of accounts and websites that offer supposedly free accounts can be difficult to wade through.  I just finished doing so and I found one that is easy to setup and use and it IS free, so I thought I'd share.

Instructions to get your account may be found here http://www.nvita.org/free-shells.aspx 
Unfortunately the website is running Micro$oft IIS* but the shell runs on Ubuntu.

Snippet from my session
youruserid@ubuntu:~$ uname -a
uname -a
Linux ubuntu 2.6.35-28-generic-pae #50-Ubuntu SMP Fri Mar 18 20:43:15 UTC 2011 i686 GNU/Linux
youruserid@ubuntu:~$ cat /etc/*release*
cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick
DISTRIB_DESCRIPTION="Ubuntu 10.10"
youruserid@ubuntu:~$ bash --version
bash --version
GNU bash, version 4.1.5(1)-release (i686-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

For those who are stuck on Windoze to ssh to the box you can use my favourites
*Weirdly Netcraft what's that site runing reports it as running Microsoft-IIS/6.0  on FreeBSD that is a little disturbing.

Wednesday, November 24, 2010

I lost/forgot mysqld root password

Oops, it happens, you install quickly set a good password then promptly forget to record it.
What a pain, but easily remedied using the command line!
  1. stop mysqld
    service mysqld stop 
  2. create a text file for example mysqld.reset.password containing the following 2 lines
    update mysql.user set password=password('yournewpassword') where user='root';
    flush privileges;
  3. load mysqld using the text file as input
    mysqld_safe --init-file ~/mysqld.reset.password
  4. delete your text file, for cleanliness & security reasons
    rm ~/mysqld.reset.password
  5. start mysqld
    service mysqld start