SSH how to’s & commands

Basics

  • cd: change directories
  • ls: list files in current directory

cdSSH with iterm on Mac

  1. Open iterm
  2. Enter command “SSH user@IP” (e.g. “SSH [email protected]
  3. Might need to also enter -p2200 for KH VPS
  4. You will be prompted for password, enter and you’ll be logged in.

grep search command

grep -winr “string to search for” ./* 

./* = current directory

Or 

Navigate to the folder you want to search and use:

grep -rl “search string here” *

This will show the file names

How to compress a file with SSH

From main root run this command

zip -r backupfilename.zip sourcedirectory/

E.g. (from 1 directory back from public_html) zip -r public_htmlbackup9.8.18.zip public_html/

How do I uncompress a file with SSH
If a file ends in .zip (for example, file.zip), type:
unzip file.zip

If a file ends in .tar (e.g., file.tar), type:
tar -xvf file.tar

If a file ends in .gz (for example, file.gz), type:
gzip -d file.gz

If a file ends in .tar.gz (e.g. file.tar.gz), type:
gzip -d file.tar.gz
and then
tar -xvf file.tar

If a file ends in .tgz (e.g. file.tgz), type:
tar -xvzf file.tgz

Change Host File

  1. type: sudo nano /etc/hosts and then hit return.
  2. Enter your administrator password and then hit return.
  3. You’re now in the Nano text editor.
    1. Use cursor to navigate to bottom of file
  4. Add your line of code i.e. 
  5. 111.222.33.111 domain.com www.domain.com

40.69.186.191:990

Delete files/folders

Folder: rm -rf foldername/

File: rm myFile.txt myFile1.txt myFile2.txt
All files in a folder: rm -rf *

CHMOD – Change File Permissions

Syntax: chmod -R 755 /home/camelbac/public_html/new

Note: this changes all files and folders, which screws things up.

Josh Notes

Backup publichtml only, run from web/(websitename)

Ls – list folders/files in current directory

Cd location – changes current directory