User Tools

Site Tools


tutorials:remote_access

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:remote_access [2011/02/01 02:42] chkuotutorials:remote_access [2019/01/11 17:35] (current) – [Key] chkuo
Line 1: Line 1:
 ====== Remote access ====== ====== Remote access ======
  
-===== ssh ===== +===== SSH =====
-''ssh'' (SSH client) is a program for logging into a remote machine. The typical usage is ''ssh user@hostname'', for example:  +
-<code bash> +
-$ ssh jake@168.192.1.1 +
-</code>+
  
-If the username is the same in the two machines (i.e., the local workstation and the remote server), the username can be omitted: +==== Login ==== 
-<code bash> +''ssh'' (SSH client) is a program for logging into a remote machine. The typical usage is ''ssh user@hostname'', for example: <code bash>ssh jake@168.192.1.1</code> 
-ssh 168.192.1.1 + 
-</code>+If the username is the same in the two machines (i.e., the local workstation and the remote server), the username can be omitted: <code bash>ssh 168.192.1.1</code> 
 + 
 +**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.  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. 
  
-To logout once you are done: +==== Logout ==== 
-<code bash> +To logout once you are done, type: <code bash>exit</code>
-exit +
-</code>+
  
 You will return to the shell running on your local machine, just like before you logging into the remote server. You will return to the shell running on your local machine, just like before you logging into the remote server.
  
-==== ssh key ==== +==== Key ==== 
-To generate key-pairs, use: <code bash>ssh-keygen -t 'rsa'</code> +To generate key-pairs, use: <code bash>ssh-keygen -t rsa -b 4096</code>
  
-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.+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 (this file should be owned by the user and have the ''644'' permissions).
  
 +If the home directory is encrypted, ''authorized_keys'' would not work while within the home directory before the user is logged in. Move the ''authorized_keys'' file and modify ''/etc/ssh/sshd_config'' accordingly.
 +For example (see [[https://help.ubuntu.com/community/SSH/OpenSSH/Keys#Troubleshooting]]:
 +  * set up ''/etc/ssh/<username>'' (owned by user, 755 permissions). 
 +  * in ''/etc/ssh/sshd_config'', add ''AuthorizedKeysFile    /etc/ssh/%u/authorized_keys''
 +  * restart sshd: ''sudo service ssh restart''
  
-===== scp ===== +==== Keep alive ==== 
-''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. +To prevent the ssh sessions from being disconnected due to inactivity, add the following lines to ''/etc/ssh_config'' on the client
- +<code> 
-For example, to copy a file (foo.txt) from the home directory (~) to the home directory in the remote server, use+ServerAliveInterval 60 
-<code bash+ServerAliveCountMax 60
-$ scp ~/foo.txt 168.192.1.1:~+
 </code> </code>
 +This sends a signal every 60 seconds for a maximum of 60 times (one hour) from the client to the server.
  
-Reversely, to copy the file from the remote server back to the local workstation: +If you do not have the permission to make this modification, put those lines to ''~/.ssh/config'' (create the file is necessary). 
-<code bash> + 
-scp 168.192.1.1:~/foo.txt ~  + 
-</code>+===== SCP ===== 
 +''scp'' copies files between hosts on a network. The typical usage is: <code bash>scp user@host1:file1 user@host2:file2</code> 
 + 
 +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: <code bash>scp ~/foo.txt 168.192.1.1:~</code> 
 + 
 +Reversely, to copy the file from the remote server back to the local workstation, use: <code bash>scp 168.192.1.1:~/foo.txt ~</code>
  
 Some commonly used options include: Some commonly used options include:
Line 44: Line 52:
   * ''-r'': Recursively copy entire directories.   * ''-r'': Recursively copy entire directories.
  
-For example, to preserve the property of the file being copied, use: +For example, to preserve the property of the file being copied, use: <code bash>scp -p ~/foo.txt 168.192.1.1:~</code>
-<code bash> +
-scp -p ~/foo.txt 168.192.1.1:~ +
-</code> +
- +
-To copy an entire directory: +
-<code bash> +
-$ scp -r ~/foo_dir 168.192.1.1:+
-</code>+
  
 +To copy an entire directory, use: <code bash>scp -r ~/foo_dir 168.192.1.1:~</code>
tutorials/remote_access.1296499325.txt.gz · Last modified: by chkuo