Posts tagged Sysadmin
When I run
ls, I run it as
lsays to put each file or folder on its own line
Asays to list all files – hidden files, backups, etc. – but omit the current directory (
.) and the parent directory (
hsays to use human readable file sizes –
gsays to omit the user
osays to omit the group
Occasionally I use the
-R parameter, which lists folders and subfolders recursively.
Sometimes the simplest sysadmin tasks are the hardest to find straightforward answers to. Recently, I spent too much time trying to change the
root password on a fresh
root password for MySQL has security implications; there is no shortage of paranoid nerds describing how the world might end if you do what I’m about to do. If you understand the security implications of setting the
root MySQL password, and still want to do it anyway, here’s how:
And, once logged in to the
UPDATE mysql.user SET Password=PASSWORD('the password goes here') WHERE User='root'; FLUSH PRIVILEGES;
The systemwide crontab file on CentOS can be found at
You can edit it with your editor of choice, e.g.
sudo vi /etc/crontab
How to start Apache:
sudo apachectl start
How to stop Apache:
sudo apachectl stop
How to restart Apache:
sudo apachectl restart
N.B. I am on OS X Mavericks. It ships with Apache 2.
Often as part of an hourly, daily, or weekly server backup bash script, you will wish to dump all MySQL databases to disk as a gzip file. This way, in the case that any of your databases suffer from corruption or user error, you will have a backup.
Simply put this command inside your cron-scheduled backup bash script, substituting the
PASSWORD, and the destination path with your info:
#!/bin/bash mysqldump -u USERNAME -pPASSWORD --all-databases --routines| gzip > /mysqlbackups/MySQLDB_`date '+%m-%d-%Y'`.sql.gz
In the last few years, ruby has taken the world by storm. With different projects dependent on different versions of Ruby, many Rails, Jekyll, and Sinatra programmers have installed RVM to manage their ruby versions in OS X. I am one of them.
While RVM is awesome, it can make some previously simple tasks difficult. One such example is creating a
launchd daemon that invokes a ruby script. If your gems are installed with RVM, you will need to use RVM to write your daemon. That’s where it gets complicated.
This tutorial teaches you how to schedule a ruby task on OS X using
launchd. You can schedule any ruby file to be run. It will be executed using the RVM ruby version of your choice.
How to start Apache 2:
sudo service apache2 start
How to stop Apache 2:
sudo service apache2 stop
How to restart Apache 2:
sudo service apache2 restart
How to reload Apache 2:
sudo service apache2 reload
Reloading is useful if you change a virtualhost file, since it will not actually stop Apache. Therefore, your websites will not go offline (even for a few seconds).
launchd. Do not use
cron on OS X.
launchd man page.
If you make a custom bash script in OS X, and you want everyone on the system to be able to access it, this is the directory where you should save it:
GROUPNAME with the user you wish to add to a group:
sudo adduser USERNAME GROUPNAME
If you add a bunch of new files to an SVN-managed folder, you do not need to
svn add... each file manually. Just
cd into the folder and type:
svn add ./ --force
Run this command, replacing
GROUP with the user and group to which you would like the files changed; substitute
DIRECTORY for the folder whose ownership you would like to change:
chown -R USER:GROUP ./DIRECTORY
There are many cases where you will want to dump a MySQL database. Examples include: backing up a website, migrating a website to a new server, moving from a development machine to a production server, and more.
Simply run this command, substituting the
FILENAME with your info. When you run this command, it will prompt you for the MySQL password for the
USERNAME you provided:
mysqldump -u USERNAME -p DATABASE_NAME > FILENAME.sql
Look for the line that starts with
Release:. The following number is your version number. As of this writing, mine says
Release: 12.04, which means I am running Ubuntu version
You will see something like this:
mail_version = 2.9.6. In this case, your Postfix version is
First, create a new, empty MySQL database from the MySQL console:
create database DATABASE_NAME;
Then, import the
.sql file into it:
mysql -u root -p -h localhost DATABASE_NAME < FILE_TO_IMPORT.sql
The MySQL console allows you to directly execute SQL commands, without having to use a programming language adapter such as PHP, Ruby, or Python.
Run this command, replacing
USERNAME with your MySQL username; you will be prompted for the password.
mysql -u USERNAME -p -h localhost
sudo /etc/init.d/postfix restart
N.B. I am running Ubuntu 12.04 LTS and Postfix 2.9.6.
Whenever I upload a new folder to my website, I set its permissions and ownership:
sudo chmod -R g+rw /var/www/my-website.com/new-folder/ sudo chown -R www-data:www-data /var/www/my-website.com/new-folder/
This guide will show you how to quickly set up a new website in Apache 2 using virtualhosts. Follow these instructions exactly as written, down to the character: trailing slashes, case, line breaks, etc.
Start by firing up a terminal, and creating a folder for the new website:
In order for this to work, the
unzip command must be installed. If you do not have
unzip on your system, install it using the package manager for your distro (apt-get, etc.).
I have written at length about how administering a Linux server is a nightmare. It does not matter how smart, experienced, or nerdy you are. Everyone who uses Linux bangs their head against a wall from time to time.