Sunday, August 09, 2009

Reset MySQL root password


Step 1
root@amir:~# /etc/init.d/mysql stop

Step 2
root@amir:~# /usr/bin/mysqld_safe --skip-grant-tables &
[1] 6709
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6763]: started

Step 3
root@amir:~$ mysql --user=root mysql
Enter password:

mysql> update user set Password=PASSWORD('new-password') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye

Step 4
root@amir:~# /etc/init.d/mysql start
Starting MySQL database server: mysqld.

Step 5
root@amir:~# mysql --user=root --pass=new-password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye




Saturday, August 08, 2009

Installing rails in FreeBSD

I installed the following via the ports tree:

  • devel/subversion
  • devel/ruby-gems
  • databases/rubygem-activerecord
  • lang/ruby18
  • converters/ruby-iconv
gem18 install rails
For security reason, FreeBSD only allows su to root user,
if user is member of wheel group. Wheel group is a special group for administration purpose. Add your normal user to this group using pw command using following:
# pw user mod username -G wheel

So to add user amir to group wheel run command as follows:
# pw user mod amir -G wheel
# groups amir

amir wheel

Now su will work for amir.


You can disable this behavior complete for all users (not recommended until and unless you trust ALL of users):
1) Open pam configuration file for su using text editor:
# vi /etc/pam.d/su

2) Look for following line and comment it out:
Line:
auth requisite pam_wheel.so no_warn auth_as_self noroot_ok exempt_if_empty
Replace with:
#auth requisite pam_wheel.so no_warn auth_as_self noroot_ok exempt_if_empty

3) Now all users can use su command.