Introduction to SSH (Secure Shell)
Secure Remote Login
When you enter commands into your local terminal, the characters are transmitted from your keyboard to the shell, which then displays them on your screen. When you execute a command, the shell processes it and shows the result. To run commands on a different machine, such as a server that handles a database, you need to perform a remote login. This involves using a client program to establish a connection with the remote machine, which must be running a remote login server. The client program sends your login information (i.e., ssh username and password) to the server, and if the authentication is successful, it opens a shell session on the remote machine for you. This SSH (Secure Shell) protocol facilitates secure remote logins by encrypting the data transmitted over the network, thereby protecting against eavesdropping, hijacking, and other security threats.
Key Concepts
- SSH: A secure alternative to remote login and file transfer.
- SSH Daemon (sshd): The server-side program that accepts connections from SSH clients.
- SSH Client: The program used to connect to the remote SSH server.
- SSH Keys: Generated in pairs (public and private). The public key can be shared, while the private key remains on your machine.
Secure Shell (SSH)
To access a remote computer, you must login via SSH, which would require a username and password. Each remote server has a different address. In this example, we will use @remoteComputerAddress
. To access the remote computer, you would execute the following code, replacing the example server address:
ssh username@remoteComputerAddress
To check which system you're currently connected to, you can use the command: hostname
. Once logged in, you'll be able to interact with the remote shell just as you would with your local shell.
To exit the remote session, either type exit
or press Control-D
.
Secure Copy
SCP (Secure Copy Protocol) is used to securely copy files to or from a remote machine over the SSH connection. To securely transfer a file from your local computer to a remote server, use the following command:
Copying Files
To securely copy of file from your local computer onto a remote server, use:
scp localFile.txt username@remoteComputerAddress:/path/to/remote/directory/
To securely copy a file from a remote server to your local computer, use:
scp username@remoteComputerAddress:/path/to/remoteFile.txt /local/directory/
Copying Directories
To securely copy an entire directory and its contents recursively, use the -r
flag:
scp -r username@remoteComputerAddress:/path/to/remoteDirectory/ /local/directory/
Important Note
The colon :
is used to differentiate between local and remote paths. For example:
scp file.txt user@remotehost:/remote/path/
In this example, file.txt
is copied to /remote/path/
on remotehost
. Without the colon, SCP will attempt to create a file named user@remotehost
on your local machine.
High Performance Computing (HPC)
High performance computing (HPC) refers to systems that are able to operate at higher speeds, that have more memory and storage, and have faster connections with other computer systems. HPC systems are used for computationally intensive tasks and often involve connecting to large computing systems remotely. Specifically, we are able to remotely access and utilize large-scale computing systems, often referred to as "clusters", "supercomputers", or "systems for HPC". For more information about HPC clusters, visit the Carpenter's "Why Use a Cluster?" tutorial
.Interacting with these systems is typically done via a command-line interface. To connect to an HPC system, we use ssh
to connect remotely. As outlined above, the standard syntax follows this format: ssh yourUsername@some.computer.address
.
To check if your connection worked, you can look at your command prompt, it should now look something like [yourUsername@some.computer.address ~]$
. Alternatively, you can run hostname
.
Modules in HPC
Modules are used to manage software environments in HPC systems. They allow users to switch between different software versions and manage dependencies.
Module Commands
- List Available Modules:
module avail
- Retrieve Specific Module:
module spider <software-name>
- Load a Module:
module load <software-name>
- List Loaded Modules:
module list
- Swap Modules:
module swap <old-module> <new-module>
- Unload a Module:
module unload <software-name>
- Purge All Modules:
module purge
- Reset Modules:
module reset
- Help with Modules:
module help
module avail
module spider <software-name>
module load <software-name>
module list
module swap <old-module> <new-module>
module unload <software-name>
module purge
module reset
module help
For more information on module commands, refer to this documentation.
Additional Resources
- High Performance Computing (HPC) Resources: HPC Shell Guide
- Curated HPC Resources: Awesome HPC