User Tools

Site Tools


tutorials:remote_access

This is an old revision of the document!


Table of Contents

Remote access

SSH

Login

ssh (SSH client) is a program for logging into a remote machine. The typical usage is ssh user@hostname, for example:

ssh jake@168.192.1.1

If the username is the same in the two machines (i.e., the local workstation and the remote server), the username can be omitted:

ssh 168.192.1.1

Note: when connecting to a remote host for the first time, expect to see a warning about the authenticity of the host can't be established. Simply type yes will add the host key to the ~/.ssh/known_hosts file on the local machine. Unless the configuration changes on either machine, this warning will not appear again.

After you logged into the remote server via ssh, the shell runs just like you are sitting in front of the remote server. You can execute all your shell command as you normally would.

Logout

To logout once you are done, type:

exit

You will return to the shell running on your local machine, just like before you logging into the remote server.

Key

To generate key-pairs, use:

ssh-keygen -t 'rsa'

This command will create a pair of private key (~/.ssh/id_rsa) and public key (~/.ssh/id_rsa.pub). To enable authentication on a remote host, append the public key to the ~/.ssh/authorized_keys file in the remote host.

SCP

scp copies files between hosts on a network. The typical usage is:

scp user@host1:file1 user@host2:file2

Similar to the example in ssh, the username can be omitted if it is the same in the two hosts; in addition, the local host can be omitted as well.

For example, to copy a file (foo.txt) from the home directory (~) of the local workstation to the home directory in the remote server, use:

scp ~/foo.txt 168.192.1.1:~

Reversely, to copy the file from the remote server back to the local workstation, use:

scp 168.192.1.1:~/foo.txt ~

Some commonly used options include:

  • -p: Preserves modification times, access times, and modes from the original file
  • -r: Recursively copy entire directories.

For example, to preserve the property of the file being copied, use:

scp -p ~/foo.txt 168.192.1.1:~

To copy an entire directory, use:

scp -r ~/foo_dir 168.192.1.1:~
tutorials/remote_access.1323746072.txt.gz · Last modified: 2011/12/13 11:14 by mushroom