Vi/Ex script line mode
This would edit “/etc/ld.so.conf” which is owned by root and allow you to add “/usr/local/BerkeleyDB.4.6/lib” to the end of the file. “$” represents the last line of the file (this is determined by Vi/Ex). If you were to put the number “5″ in place of “$” and there was only 2 lines in the file this would fail since that line does not exist.
sudo ex - /etc/ld.so.conf << BLAH
$ append
/usr/local/BerkeleyDB.4.6/lib
.
wq
BLAH
This will search “/etc/openldap/slapd.conf” for “var//” and replace that with “var/” AND “etc//” and replace that with “etc/”.
sudo ex - /etc/openldap/slapd.conf << BLAH
g/var\/\//s//var\//g
g/etc\/\//s//etc\//g
wq
BLAH
Reference Here for a command guide.
Reference Here for a tutorial.
Password recovery Linux CentOS/RedHat
First, try single user. If you don’t see either a LILO or GRUB boot screen, try hitting CTRL-X to get one. If it’s LILO, just type “linux single” and that should do it (assuming that “linux” is the lilo label). If GRUB, hit ‘e”, then select the “kernel” line, hit “e” again, and add ” single” (or just ” 1″) to the end of the line. Press ENTER, and then “b” to boot.
You should get a fairly normal looking boot sequence except that it terminates a little early at a bash prompt. If you get a “Give root password for system maintenance”, this isn’t going to work, so see the “init” version below.
If you do get the prompt, the / filesystem may not be mounted rw (although “mount” may say it is). Do
mount -o remount,rw /
If that doesn’t work (it might not), just type “mount” to find out where “/” is mounted. Let’s say it is on /dev/sda2. You’d then type:
mount -o remount,rw /dev/sda2
If you can do this, just type “passwd” once you are in and change it to whatever you like. Or just edit /etc/shadow to remove the password field: move to just beyond the first “:” and remove everything up to the next “:”. With vi, that would be “/:” to move to the first “:”, space bar once, then “d/:” and ENTER. You’ll get a warning about changing a read-only file; that’s normal. Before you do this, /etc/shadow might look like:
root:$1$8NFmV6tr$rT.INHxDBWn1VvU5gjGzi/:12209:0:99999:7:-1:-1:1074970543
bin:*:12187:0:99999:7:::
daemon:*:12187:0:99999:7:::
adm:*:12187:0:99999:7:::
and after, the first few lines should be:
root::12209:0:99999:7:-1:-1:1074970543
bin:*:12187:0:99999:7:::
daemon:*:12187:0:99999:7:::
adm:*:12187:0:99999:7:::
You’ll need to force the write: with vi, “:wq!”. (If that still doesn’t work, you needed to do the -o remount,rw, see above).
Another trick is to add “init=/bin/bash” (LILO “linux init=/bin/bash” or add it to the Grub “kernel” line). This will dump you to a bash prompt much earlier than single user mode, and a lot less has been initialized, mounted, etc. You’ll definitely need the “-o remount,rw” here. Also note that other filesystems aren’t mounted at all, so you may need to mount them manually if you need them. Look in /etc/fstab for the device names.
Keep this in mind if you have a Linux machine in a publically accessible place : without more protection, it’s not usually hard to recover a lost root password, which means it’s just as easy for someone to CHANGE it, or access root without your knowlege.
Another way to do this is to remove the password from /etc/shadow. Just in case you screw up, I’d copy it somewhere safe first. You want to end up with the root line looking something like this:
# original line
root:$1$EYBTVZHP$QtjkCG768giXzPvW4HqB5/:12832:0:99999:7:::
# after editing
root::12832:0:99999:7:::
If you are having trouble with editing (you really do have to learn vi one of these days), you could just (after making a copy, of course) just
echo "root::12832:0:::::" > /mnt/etc/shadow
or, if you were in single user mode
echo "root::12832:0:::::" > /etc/shadow
and then fix things up when rebooted.
rancid-rev_sh.txt
shell script to diff rancid configs in cvs
#!/bin/bash # rancid-rev - for use with rancid implementation. # -- mikeb 10/05/00 # -- lancev 01/12/06 CVSROOT='/usr/local/rancid/var/CVS'; export CVSROOT; cd /usr/local/rancid/var/networking if [ -z "$1" ]; then while [ -z "$router" ]; do echo -n "Router name: " read router done else router=`echo $1 | sed 's/.abc.com//g'` router="$1" fi #if [ -z "$2" ]; then # while [ -z "$date" ]; do # echo -n "Date (YYYY-MM-DD): " # read date # done #else # date="$2" #fi if [ -z "$2" ]; then #cvs history -D $date -e -a -w $router | ( while read a cvs history -e -a -w $router | ( while read a do if [ ! -z "`echo $a | cut -f6 -d' ' | grep \"[0-9]\.[0-9][0-9]\"`" ]; then echo $a | sed 's/^.\ //' fi done ) | egrep -v "configs$" | sort cvsdisplayed="yes" echo -n "Enter 1st revision number: " while [ -z "$rev" ]; do read rev done else rev=$2 fi if [ -z "$3" ]; then echo -n "Enter a 2nd revision number (y/N): " read rev2ans if [ "$rev2ans" = "y" ]; then if [ -z "$cvsdisplayed" ]; then cvs history -e -a -w $router | ( while read a do if [ ! -z "`echo $a | cut -f6 -d' ' | grep \"[0-9]\.[0-9][0-9]\"`" ]; then echo $a | sed 's/^.\ //' fi done ) | egrep -v "configs$" | sort fi echo -n "Enter 2nd revision number: " while [ -z "$rev2" ]; do read rev2 done fi else rev2=$3 fi cd configs/ if [ -z "$rev2" ]; then cvs diff -Naur $rev $router | more else cvs diff -r $rev -r $rev2 $router | more fi # # Currently it will only build a config from # the 1st rev against the current config in cvs. # echo -n "Build config based on diff? (y/N): " read build if [ "$build" = "y" ]; then cp $router $HOME cvs diff -r $rev $router | ( cd $HOME; patch -R ) echo "Config based on revision $rev in $HOME/$router" fi
Creating a new user and permissions in mysql
Typically in MySQL you need to create a database for an application to use and a user which that application will use to access that database. Here is how I normally do this.
Create the database using mysqladmin
sudo mysqladmin -u root -p create
Create a user with basic permissions
First we need to select the mysql database so we can create a user.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
Now we need to create the database_user with permissions.
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database_name.* TO 'database_user'@'localhost' IDENTIFIED BY 'database_user_password';
Query OK, 0 rows affected (0.02 sec)