Sometimes it’s a little bit of a pain to constantly type your password every time you log in to a server. If you are pushing code, moving files, backing up data, typing your password at each step of the way can be annoying. By setting up public/private keys between your local machine and the remote server you can eliminate that step.
Type the following on the local machine:
You will see the following after typing the command above. You can press enter and skip the question when you’re asked for a file name, but for the passphrase try not to leave it blank:
Generating public/private dsa key pair.
Enter file in which to save the key (/Users/amitsamtani/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/amitsamtani/.ssh/id_dsa.
Your public key has been saved in /Users/amitsamtani/.ssh/id_dsa.pub.
If you did not change the file name copy the contents of ~/.ssh/id_dsa.pub to the remote servers ~/.ssh/authorized_keys file. Append the contents to the end of the file.
After this is complete, on your first attempt to ssh into the remote server you will be presented with a prompt by OS X to type the id_dsa.pub passphrase. Type the passphrase into the prompt and save it in your keychain.
Now you can log in to the server without the need of the password.
First tar/gzip the blog and the database:
tar -cf old_blog.tar blog/
gzip old_blog.tar
mysqldump -h hostname.com -u username -p database_name > dump.sql
gzip dump.sql
Bring the blog and database to your local machine and set it up. For simplicity sake we will assume that the database name, username and password is the same as your live server.
scp user@hostname.com:/path/to/files/old_blog.tar.gz .
scp user@hostname.com:/path/to/files/dump.sql.gz .
tar -xzvf old_blogtar.gz
tar -xzvf dump.sql.gz
mysql -h localhost -u user -p database_name < dump.sql
Log in to your database and change the values of siteurl and home in the wp_options table to point to your local machine’s domain:
update wp_options set option_value = 'http://localhost:8888/domain.com' where option_name in ('siteurl','home);
I just realized I do not have a copy of wget on my installation of Snow Leopard. If you need it, its just a matter of getting the latest code via curl and installing.
curl -O http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz
tar -xzvf wget-latest.tar.gz
cd wget-1.12
./configure --prefix=/usr/local
make
sudo make install
Now lets use wget in an example:
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress new_blog
Very nice!
Update (2009-10-23): This works well for adding a prefix to files in a folder. To add a suffix to a file read “Renaming files – Adding a suffix to the file name” instead.
Here is a quick way to rename multiple files using bash.
Objective: Rename all image files in a directory in uppercase, to lowercase and append a tn_ prefix.
Step 1: Prepare a working directory
mkdir test
cd test
touch FILE_1.jpg
touch FILE_2.jpg
touch FILE_3.jpg
Step 2: Test first – print out all files in lower case
for i in *.jpg; do echo $i | tr [:upper:] [:lower:]; done
Output
file_1.jpg
file_2.jpg
file_3.jpg
Step 3: Test first – print out all files prefixed with tn_ and lower cased
for i in *.jpg; do echo "tn_"$i | tr [:upper:] [:lower:]; done
Output
tn_file_1.jpg
tn_file_2.jpg
tn_file_3.jpg
Step 4: Rename the files in the directory
for i in *.jpg; do mv $i `echo "tn_"$i | tr [:upper:] [:lower:]`; done
Done!
This last week I wanted to set up a git repository on dreamhost and came across this article on the Autopragmatic blog. The author provides easy step by step instructions to set up the repository and instructions to work with git. Here I provide a quick summary of what I consider the most important sections, if you’d like to read the original article and get a more in-depth understanding I recommend reading the original article.
Step 1: Compile git on dreamhost (change USER to your username)
mkdir ~/src
cd ~/src
wget http://www.kernel.org/pub/software/scm/git/git-1.6.5.rc1.tar.gz
tar xzf git-1.6.5.rc1.tar.gz
cd git-1.6.5.rc1
./configure --prefix=/home/USER/ NO_CURL=1 NO_MMAP=1
make
make install
git --version
Step 2: Automate repository creation. Insert this function in your ~/.bashrc. Change gitdir to point to the path where your repositories will reside.
newgit()
{
if [ -z $1 ]; then
echo "usage: $FUNCNAME project-name.git"
else
gitdir="/home/USER/git/$1"
mkdir $gitdir
pushd $gitdir
git --bare init
git --bare update-server-info
chmod a+x hooks/post-update
touch git-daemon-export-ok
popd
fi
}
Thats it!
Now, what can be done:
1. Create new repository while ssh’d into your dreamhost account:
2. Create new repository remotely
ssh USER@MACHINE newgit repo-name.git
3. Create a new repository remotely. Clone it (check it out). Create file. Add to git. Commit. Push to repository. Make another change. Commit. Push.
ssh asamtani@amitsamtani.com newgit test.git
git clone ssh://asamtani@amitsamtani.com/home/asamtani/git/test.git
cd test
touch sample.txt
git add .
git commit -a -m "first commit"
git push --all
vi sample.txt
git commit -a -m "second commit"
git push
- password will be asked when a new repository is created, a repository is cloned and when a push is made
- when the clone is made a warning will be issued that you are cloning an empty repository
warning: You appear to have cloned an empty repository.
- you need to pass the –all flag when doing the first push or you will get an error like this:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://asamtani@amitsamtani.com/home/asamtani/git/test.git'
Again, read the original article for a more in depth explanation of what is going on and what more you can do.