Connecting to Remote Servers via SSH
A super-quick guide on how to leverage SSH keys for remote connections (on Unix)
Connecting
- Here is the resource I checked.
I’ll assume that you have a working SSH key ready to go — or check out this guide to set things up.
The command is stunningly simple. Open your terminal and type in the following command.
# username is your user handle in the system
# hostname can be something like: server01-node02.company.local
ssh username@hostname
After hitting enter you might see a bunch of output printed to your screen, also the host will likely ask for your password as a second layer of authentication. There will not be a second window popping up or anything (at least not by default) — it will run directly in your terminal.
From here on out you can interact with the server as you would with your terminal:
cd
into directoriesls
thingsmkdir
's- or whatever the system will permit you to do
After taking care of business you can quit your session by typing exit
in the terminal or press ctrl + d
# simply disconnect by executing
exit
The one basic thing that you will likely want to do after having established a connection: Transferring files
Downloading
scp username@hostname:/remote/path/to/file /local/folder/path/
To download files you have to specify the connection again like you did when connecting to the host. Additionally, you provide the path to the file or folder you want to download. Notice the colon between the hostname and path.
Uploading
scp /local/path/to/file username@hostname:/remote/path/to/folder
This works like downloading, only the path specification is reversed. We define the local path first, then the remote path.
Of course, there is much more you can do with your access. However, I found most people just want this one basic thing and nothing to do with more specific stuff like SSH tunneling or preserving terminal sessions, etc.