Posts tagged Sysadmin
How I use ls on Linux
When I run ls, I run it as ls -lAhog:
lsays to put each file or folder on its own lineAsays to list all files – hidden files, backups, etc. – but omit the current directory (.) and the parent directory (..)hsays to use human readable file sizes –1.5Ginstead of1628688384gsays to omit the userosays to omit the group
Occasionally I use the -R parameter, which lists folders and subfolders recursively.
How to change the root password on MySQL
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 mysql install.
Changing the 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:
mysql -urootAnd, once logged in to the mysql console:
UPDATE mysql.user SET Password=PASSWORD('the password goes here') WHERE User='root';
FLUSH PRIVILEGES;Location of the systemwide crontab on CentOS
The systemwide crontab file on CentOS can be found at
/etc/crontabYou can edit it with your editor of choice, e.g.
sudo vi /etc/crontabHow to start and stop Apache in OS X
How to start Apache:
sudo apachectl startHow to stop Apache:
sudo apachectl stopHow to restart Apache:
sudo apachectl restartN.B. I am on OS X Mavericks. It ships with Apache 2.
How to dump all MySQL databases to a gzip file from inside a bash script
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 USERNAME, 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.gzCreating a ruby launchd task with RVM in OS X
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 and stop Apache 2 in Ubuntu Linux
How to start Apache 2:
sudo service apache2 startHow to stop Apache 2:
sudo service apache2 stopHow to restart Apache 2:
sudo service apache2 restartHow to reload Apache 2:
sudo service apache2 reloadReloading 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).
In OS X, should I use cron or launchd?
Use launchd. Do not use cron on OS X.
Source: the launchd man page.
Where to put custom bash scripts in OS X
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:
/usr/local/binHow to add a user to a group in Linux
Simply replace USERNAME and GROUPNAME with the user you wish to add to a group:
sudo adduser USERNAME GROUPNAMEHow to add all new files in a folder to SVN
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 ./ --forceHow to change ownership recurisively in Linux
Run this command, replacing USER and 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 ./DIRECTORYHow to dump a MySQL database
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 USERNAME, DATABASE_NAME, and 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.sqlHow to get the Ubuntu version from the commandline
lsb_release -aLook 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 12.04.
How to get your Postfix version
postconf mail_versionYou will see something like this: mail_version = 2.9.6. In this case, your Postfix version is 2.9.6.
How to import a .sql file into a MySQL database
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.sqlHow to list all users in Linux
cat /etc/passwdHow to open the MySQL console
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 localhostHow to restart postfix in Ubuntu Linux
sudo /etc/init.d/postfix restartN.B. I am running Ubuntu 12.04 LTS and Postfix 2.9.6.
How to set folder permissions and ownership for Apache website data
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/How to set up a new virtualhost domain in Apache 2
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:
mkdir /var/www/my-new-website.comHow to unzip a file on the Linux commandline
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.).
unzip ./FILE_NAME.zipMy minimal Apache2 virtualhost file
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.