To use SSH you need an SSH Terminal.
On Mac, there is a program called Terminal. On Windows computers many users use PuTTY.
Connecting to SSH
ssh USERNAME@SERVERNAME
(for example: ssh [email protected]
)
You will be prompted for your password and can log in.
Basic file system commands
man [commandname]
Shows the help page for any command
ls -la
List files in a directory
cd [directoryname]
Go into a directory
cd ..
Go up one level
cd ~
Go to your home directory (typically /kunder/group/username)
pwd
Display current path
cat [filename]
Print contents of file to console
nano [filename]
A handy text editor with easy controls and onscreen help (certainly easier than vi or vim)
gzip / gunzip
Pack/unpack .gz files
zip / unzip
Zip/unzip .zip files
tar -xvf [filename]
Unpack a .tar archive
tar -xvzf [filename]
Unpack a .tgz archive
Permissions on files
Many online articles tell you to set permissions on files in order to make something work. Our file system is properly configured, and unless you are doing any advanced sharing of files across hosts – your directories only need 700 permissions, and your files need 600 to be usable by the web server.
chmod 700 [directoryname]
chmod 600 [filename]
To recursively fix permissions for all files in your /public
folder, run the following commands from your home directory.
find public/ -type d -exec chmod 700 {} \;
find public/ -type f -exec chmod 600 {} \;
Importing and exporting databases
To export the database to a text file, SQL dump (.sql) run:
mysqldump -u USERNAME -p DATABASENAME > FILENAME.sql
To make sure database dumps are consistent, the –single-transaction should be added, like:
mysqldump --single-transaction -u USERNAME -p DATABASENAME > FILENAME.sql
To import a database from an SQL dump, run:
mysql -u USERNAME -p DATABASENAME < FILENAME.sql
Viewing and examining log files
The Apache web server stores its logs in the ~/logs/
folder which you can find in the root of your site when you log in with SSH or SFTP.
Accesslog
Contains all requests that are passed back from the front-end web server
Errorlog
Contains all errors
The following command will display log entries as they are added in real-time:
tail -f ~/logs/*log
List everything from both the Accesslog and the Errorlog
tail -f ~/logs/Errorlog
Print only additions to the Errorlog
grep -
Finding content in files
To find an occurrence of [searchstring] in any file recursively from your current directory, write:
grep -R [searchstring] *
You can make it case insensitive by adding the -i parameter (grep -iR
…)