How to SSH

Remote access of a machine via ssh is simply done as follows

-For direct acces to machine

    ssh -p 1022 username@server_address

The -p command just specifies the port. Usually you will be logging in on port 22.

-For copying files from a remote machine

scp -P 1022 username@server_address:path_to_remote_file path_to_local_directory

-For copying to a remote machine just switch the order:

scp -P 1022 path_to_local_file username@server_address: path_to_remote_directory

What is especially useful is not having to enter a password each time you login or copy to/from the remote machine. The steps to set this up are as follows

-Generate RSA keys

    ssh-keygen

This will generate a public and private RSA pair in

    ~/.ssh/id_rsa

-Copy the public key to the remote host. For this we use ssh-copy-id. First you may need to install this using Homebrew (OSX).

    brew install ssh-copy id

Then use this to copy the public key to the remote machine

    ssh-copy-id -i ~/.ssh/id_rsa.pub -p 1022 username@server_address

-Now you should be able to ssh into the machine without having to enter a password. The public key you uploaded can be found in,

    ./ssh/authorized keys.

Rather than directly copying many files to and from a remote server it is usually easier to create a tar file:

    tar -cvzf filename.tar.gz *.txt

will create a tarball of all txt files in the directory.

For unzipping the file:

    gunzip filename.tar.gz
    tar -xvf filename.tar

tar packages all the files together into a single file and then gzip compresses the file. The list of tar flags can be found here

Categories:

Updated: