This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
other:ssh [2020/08/04 07:54] jypeter Updated the links for PuTTY |
other:ssh [2020/08/21 15:44] jypeter Reorganized a bit (esp X server) |
||
---|---|---|---|
Line 14: | Line 14: | ||
* We assume below that you have a ''my_login'' account on the remote ''remote_server'' computer, and you know your password | * We assume below that you have a ''my_login'' account on the remote ''remote_server'' computer, and you know your password | ||
- | * This page will also show some examples using the LSCE and IPSL (ciclad) servers | + | * This page will also show some examples using the LSCE and [[https://mesocentre.ipsl.fr/|IPSL Mésocentre ESPRI]] servers |
- | * Instead of a password, you can also use a set of //private and public keys// and a //passphrase// | + | * Instead of a password, you can also [[other:ssh#using_ssh_keys|use a set of private and public keys and a passphrase]] |
+ | * This is the only kind of authentication that will work if you need to use the [[https://mesocentre.ipsl.fr/|IPSL Mésocentre ESPRI]] (aka **ciclad** and **climserv**)! | ||
* Many programs are said to //work over ssh// when they implicitly use the //ssh protocol// to securely transfer their data from one server to another: ''scp'' (copy remote directories and files), ''rsync'' (synchronize remote directories and files), ... | * Many programs are said to //work over ssh// when they implicitly use the //ssh protocol// to securely transfer their data from one server to another: ''scp'' (copy remote directories and files), ''rsync'' (synchronize remote directories and files), ... | ||
Line 27: | Line 28: | ||
<WRAP center round tip 60%> | <WRAP center round tip 60%> | ||
- | Note: the following will work in a **Linux** terminal, but can also work in a //terminal// on a **Mac** or on a **Windows 10** computer (''ssh'' is directly available in ''Windows Powershell'', ''Windows Terminal'' or the old ''cmd'', but it is not the most user-friendly way to use ''ssh'' on Windows) | + | * The following will work in a **Linux** terminal, but can also work in a //terminal// on a **Mac** or on a **Windows 10** computer |
- | If you have a Windows computer, it is much easier to use [[other:putty_conf|PuTTY]] for creating an ''ssh'' connection | + | * On **Windows 10**, ''ssh'' is directly available in a ''Windows Powershell'', a ''Windows Terminal'' or the old ''cmd'', but the most user-friendly way to use ''ssh'' is to use [[other:putty_conf|PuTTY]] |
</WRAP> | </WRAP> | ||
Line 35: | Line 36: | ||
* **''ssh [options] [my_login@]remote_server''** | * **''ssh [options] [my_login@]remote_server''** | ||
* If your login is the same on the local and remote computer, you can omit the optional ''my_login@'' part:\\ e.g. just use ''ssh ssh1.lsce.ipsl.fr'' | * If your login is the same on the local and remote computer, you can omit the optional ''my_login@'' part:\\ e.g. just use ''ssh ssh1.lsce.ipsl.fr'' | ||
- | * The **first time** you connect to a **new server**, ''ssh'' will ask if you are sure of what you are doing, and then store some unique information about the remote server in the ''known_hosts'' file ([[#configuration_files|details]]). ''ssh'' will check this security information (without asking you) each time you connect to the same server, and warn you if something seems wrong\\ <code>PS C:\Users\my_login> ssh ssh1.lsce.ipsl.fr | + | * The **first time** you connect to a **new server**, ''ssh'' will ask if you are sure of what you are doing, and then store some unique information about the remote server in the ''known_hosts'' file ([[#configuration_files|details]]).\\ <code>PS C:\Users\my_login> ssh ssh1.lsce.ipsl.fr |
The authenticity of host 'ssh1.lsce.ipsl.fr (157.136.66.99)' can't be established. | The authenticity of host 'ssh1.lsce.ipsl.fr (157.136.66.99)' can't be established. | ||
ECDSA key fingerprint is SHA256:vMAvkidEg0EukP/RZwPAVuo5+TBegQFx1v8WN9pZLXg. | ECDSA key fingerprint is SHA256:vMAvkidEg0EukP/RZwPAVuo5+TBegQFx1v8WN9pZLXg. | ||
Are you sure you want to continue connecting (yes/no)? yes | Are you sure you want to continue connecting (yes/no)? yes | ||
Warning: Permanently added 'ssh1.lsce.ipsl.fr,157.136.66.99' (ECDSA) to the list of known hosts. | Warning: Permanently added 'ssh1.lsce.ipsl.fr,157.136.66.99' (ECDSA) to the list of known hosts. | ||
- | my_login@ssh1.lsce.ipsl.fr's password:</code> | + | my_login@ssh1.lsce.ipsl.fr's password:</code>\\ ''ssh'' will automatically check this security information each time you connect to the same server, and warn you if something seems wrong |
- | * Most common options: | + | ==== Most common options ==== |
- | * ''-X'': Enable //X11 forwarding//. This option will allow you to start graphical programs on the remote server | + | |
- | * If ''-X'' does not work, use ''-Y'' instead (Enable //trusted// X11 forwarding) | + | * ''-X'': **enable //X11 forwarding//**. This option will allow you to **use graphical programs on the remote server** |
- | * Using the ''-X''/''-Y'' option will automatically define the ''DISPLAY'' environment variable that is required by graphical programs on the remote server. Otherwise, ''DISPLAY'' will not be defined\\ <code>my_login@lsce5203:~$ echo $DISPLAY | + | * If ''-X'' does not work, use ''-Y'' instead (Enable //trusted// X11 forwarding) |
+ | |||
+ | * ''-A'': **enable //agent forwarding//**. This is useful when you use [[other:ssh#using_ssh_keys|ssh keys and an ssh agent]] | ||
+ | |||
+ | * ''-t command'': this option allows you to **execute a specific command on the remote server** (without displaying the output of the initial ''ssh''). We use this mostly to //chain ssh connections//, when we want to automatically go through a specific //gateway// server to access another server\\ e.g. ''ssh -A -X my_login@ssh1.lsce.ipsl.fr -t ssh -A -X obelix'' | ||
+ | |||
+ | * ''-v'': **verbose mode**. Use this option only when you can't connect, or things don't seem to work correctly. Analyzing the verbose output when you start ''ssh'' should allow you, or the [[other:newppl:starting#getting_help_from_the_lsce_system_administrators|system administrators]], to find out what is wrong | ||
+ | |||
+ | ==== Using an X server to display graphics ==== | ||
+ | |||
+ | A terminal can be used to display text information (e.g. the output of ''ls'' and ''top'', the ''vi'' editor, etc...) but also to start programs that will open new (graphical) windows outside of the initial terminal (e.g. ''evince'' to display pdf files, ''eog'' to display png/jpg images, the ''emacs'' editor, ''ferret'', etc...) | ||
+ | |||
+ | If you want to **use ''ssh'' to start graphical programs on a remote server**, you need to: | ||
+ | |||
+ | * use ''ssh -X'' (or ''ssh -Y'' if ''-X'' does not work) to connect to the remote server | ||
+ | * ''-X'': **enable //X11 forwarding//** | ||
+ | * ''-Y'': enable //trusted// X11 forwarding (low security, but you //trust// the remote server) | ||
+ | * Using the ''-X''/''-Y'' option will automatically define the ''DISPLAY'' environment variable that is required by graphical programs on the remote server. Otherwise, ''DISPLAY'' will not be defined\\ <code>my_login@lsce5203:~$ echo $DISPLAY | ||
localhost:0.0 | localhost:0.0 | ||
+ | |||
my_login@lsce5203:~$ ssh ssh1.lsce.ipsl.fr | my_login@lsce5203:~$ ssh ssh1.lsce.ipsl.fr | ||
Last login: Wed Jul 8 14:45:31 2020 from 176-142-31-75.abo.bbox.fr | Last login: Wed Jul 8 14:45:31 2020 from 176-142-31-75.abo.bbox.fr | ||
Line 53: | Line 72: | ||
[my_login@ssh1 ~]$ logout | [my_login@ssh1 ~]$ logout | ||
Connection to ssh1.lsce.ipsl.fr closed. | Connection to ssh1.lsce.ipsl.fr closed. | ||
+ | |||
my_login@lsce5203:~$ ssh -X ssh1.lsce.ipsl.fr | my_login@lsce5203:~$ ssh -X ssh1.lsce.ipsl.fr | ||
[my_login@ssh1 ~]$ echo $DISPLAY | [my_login@ssh1 ~]$ echo $DISPLAY | ||
localhost:43.0</code> | localhost:43.0</code> | ||
- | * In order to display graphical windows, you also need to have a local //X server// running! | + | * and **have a local //X server// running**!\\ An //X server// is basically a program running on your computer that understands the [[https://en.wikipedia.org/wiki/X_Window_System_core_protocol|X Windows System protocol]] used by the remote server to display graphics |
- | * Linux computer: nothing to do, an X server is already running | + | * Linux computer: nothing to do, an //X server// is already running ! |
- | * Windows: [[other:win10wsl#installing_an_x_server|install, configure and launch VcXsrv]] | + | * Windows: [[other:win10wsl#installing_an_x_server|install, configure and launch VcXsrv]] |
- | * Mac: FIXME | + | * Mac: FIXME |
- | * ''-A'': enable //agent forwarding//. This is useful when you use //ssh keys//, and an //ssh agent// | + | |
- | * ''-t command'': this option allows you to execute a command on the remote server (without displaying the output of the initial ''ssh''). We use this mostly to //chain ssh connections//, when we want to automatically go through a specific //gateway// server to access another server\\ e.g. ''ssh -A -X my_login@ssh1.lsce.ipsl.fr -t ssh -A -X obelix'' | + | |
- | * ''-v'': verbose mode. Use this option only when you can't connect, or things don't seem to work correctly. Analyzing the verbose output when you start ''ssh'' should allow you, or the [[other:newppl:starting#getting_help_from_the_lsce_system_administrators|system administrators]], to find out what is wrong | + | |
==== Useful aliases ==== | ==== Useful aliases ==== | ||
Line 93: | Line 110: | ||
[[other:putty_conf|PuTTY]] is a convenient and user-friendly //ssh client// for Windows | [[other:putty_conf|PuTTY]] is a convenient and user-friendly //ssh client// for Windows | ||
- | ===== Just transferring files ===== | + | ==== Solving common problems ==== |
- | Sometimes you just need to copy files from one server to the other. The files can be securely copied //over ssh// with the ''scp'' command | + | * You want to start a graphical program on a remote server, but get a ''Can't open display: //[NO VALUE DISPLAYED HERE]//'' error\\ <code>$ xterm & |
+ | $ xterm: Xt error: Can't open display: | ||
+ | xterm: DISPLAY is not set | ||
+ | $ echo $DISPLAY | ||
- | Note: if you work with big data files, you should keep the files were they are instead of duplicating them, and move the data processing (your scripts, etc...) to the server where the files are located (e.g. the ciclad server) | + | |
+ | </code>\\ The ''DISPLAY'' variable is probably not defined because you have not specified the ''-X'' (or ''-Y'') option when connecting to the remote server | ||
+ | |||
+ | * You want to start a graphical program on a remote server, but get a ''Can't open display: localhost://[SOME VALUE]//'' error\\ <code>$ xterm & | ||
+ | $ connect localhost port 6000: Connection refused | ||
+ | xterm: Xt error: Can't open display: localhost:12.0</code>\\ The ''DISPLAY'' variable is defined correctly, but you probably don't have a local //X server// running | ||
+ | |||
+ | * Other types of errors: remember that you can run ''ssh'' in **verbose** mode to help you determine what is wrong (''-v'' option) | ||
+ | |||
+ | ===== Copying files between servers/computers ===== | ||
+ | |||
+ | Sometimes you just need to copy files from one remote server (or your desktop) to the other. The files can be securely copied //over ssh// with the ''scp'' command | ||
+ | |||
+ | Note: if you work with big data files, you should keep the files were they are instead of duplicating them, and move the data processing (your scripts, etc...) to the server where the files are located (e.g. the ''ciclad'' server at IPSL) | ||
+ | |||
+ | ==== Copying files with scp ==== | ||
+ | |||
+ | <WRAP center round tip 60%> | ||
+ | Note: the following will work in a **Linux** terminal, but can also work in a //terminal// on a **Mac** or on a **Windows 10** computer (''scp'' is directly available in ''Windows Powershell'', ''Windows Terminal'' or the old ''cmd'', but it is not the most user-friendly way to use ''ssh'' on Windows) | ||
+ | |||
+ | If you have a Windows computer, it is much easier to use [[other:win10apps#winscp|WinSCP]] for copying files | ||
+ | </WRAP> | ||
+ | |||
+ | * **''scp [options] local_path_or_file [my_login@]remote_server:remote_path''**\\ or **''scp [options] [my_login@]remote_server:remote_path_or_file local_path''** | ||
+ | * If your login is the same on the local and remote computer, you can omit the optional ''my_login@'' part | ||
+ | |||
+ | * Most common options: | ||
+ | * ''-p'': **preserves modification times**, access times, and modes from the original file.\\ This option is **very useful** if you want the copied file(s) to have the same date/time as the original file(s). Otherwise, the time will be the time when you copy the file(s) | ||
+ | * ''-r'': **recursively** copy entire directories.\\ **You have to use this option if the source location is a directory**. ''scp -r'' will copy the complete content of the directory (including sub-directories) | ||
+ | |||
+ | ==== A recommended graphical scp client for Windows ==== | ||
+ | |||
+ | [[other:win10apps#winscp|WinSCP]] is a convenient and user-friendly //scp client// for Windows | ||
+ | |||
+ | ==== Synchronizing directories ==== | ||
+ | |||
+ | In some cases, you may want to synchronize the content of directories: | ||
+ | * because you are creating a backup | ||
+ | * because you have lots of files, possibly (very) big, and you don't want to start copying everything again if the copy fails due to temporary network problems | ||
+ | * ... | ||
+ | |||
+ | In that case, you should use the ''rsync'' command, that will only copy files that are not already in the destination (and that have not changed since the previous copy). | ||
+ | |||
+ | ''rsync'' has lots of complex options and rules, and **should be used carefully** if you do not want to lose files. This page does not cover this topic. Use ''man rsync'' or ask somebody | ||
===== Using ssh keys ===== | ===== Using ssh keys ===== | ||
+ | |||
+ | ==== What are ssh keys? ==== | ||
+ | |||
+ | |||
+ | ==== Creating ssh keys ==== | ||
+ | |||
+ | |||
+ | ==== Installing ssh keys ==== | ||
+ | |||
+ | |||
+ | ==== Using the keys ==== | ||
+ | |||
+ | |||
+ | ==== Using an ssh agent ==== | ||
+ | |||
- | ===== Using an ssh agent ===== | ||
===== More... ===== | ===== More... ===== |