Skip to content

Instantly share code, notes, and snippets.

@ravixp
Last active October 29, 2017 16:17
Show Gist options
  • Select an option

  • Save ravixp/167be654c90952c95c10b3025e200272 to your computer and use it in GitHub Desktop.

Select an option

Save ravixp/167be654c90952c95c10b3025e200272 to your computer and use it in GitHub Desktop.
SSH CheatSheets

SSH Cheatsheets

Where I am? it shows the full path

$ pwd

Move into another directory

$ cd /var/www/vhosts/example.com/conf/
$ cd ..
$ cd ~

Show all files and hidden files.

ls -alh

Move or rename file

$ mv logo.png image/logo.png
$ mv logo.png logo_new.png

Copy file or duplicate file

You can also copy an entire folder (along with all subfolders) using -R:

$ cp logo.png image/logo.png
$ cp index.php index.php_old
$ cp -R image/ image2

Remove file

Type y confirm, or n to cancel. If you don't want to be prompted, add -f to the command

$ rm index.php_old
$ rm -f index.php_old

Remove the entire folder

Please be cautious with the rm -rf command.

To make sure you're deleting the right thing, you can always run a list command first. For example:

$ ls -alh /path/to/unwanted/folder/
$ rm -rf /path/to/unwanted/folder/

Authorise

$ eval ssh-agent
$ ssh-add ~/.ssh/id_rsa

Connect to remote server

$ ssh user@remote

Add PublicKey

$ ssh-copy-id user@123.45.56.78

Alternatively, you can paste in the keys using SSH:

$ cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

Create public and private keys

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Exporting SQL (Backup SQL)

$ mysqldump -u database_name -p database_user > anyname_backup.sql

Importing SQL

$ mysql -u database_user -p database_name < anyname_backup.sql

ZIP an entire folder including subfolders and files

$ zip -r myarchive.zip myfolder

To UNZIP an archive type:

# unzip myarchive.zip

To TAR an entire folder including subfolders and files:

# tar -cpzf myarchive.tar.gzs * .htaccess

To UNTAR an archive type:

# tar -xpzf myarchive.tar.gzs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment