Table of Contents
- why does this post exist?
- conceptual overview
- using the client
- using scp
- using sftp
- setting up the host
- what about if im not on the local network?
why does this post exist?
While trying to learn SSH all the use cases and what not had been covered from the client side, assuming the infrastructure was already set up, but the basic qustion of how do I run my own SSH server and how do I find my hostname to connect were hard to come by. So here's a little post for past me.
conceptual overview
The SSH protocol is divided into the server and the client. In order to connect from your local client machine to a remote machine the remote machine must be running an ssh server. you can then use the remote machine's hostname or ip address to send along the credentials of an account to the remote machine and operate a shell on the machine as the account for which you gave credentials.
SSH is not in itself a shell, merely an encrypted tunneling tool that allows you to use existing shells on a remote machine.
using the client
using the client is as simple as running the command $ ssh user@hostname
to get to the remote user's login shell. If you want to know more there are plenty of articles explaining the client in more detail.
using scp
scp follows the syntax of $ scp [flags] [source] [target]
the source and target have multiple syntaxes but the easiest to remember is [user@]host:[/path]
using sftp
first you establish an sftp session $ sftp [user]@[host]
this will then put you inside the sftp prompt. we can then navigate the remote file system with all the typical commands such as cd
or ls
if we want to interact with the local system instead we prefix the command with an l for example lcd
to download a remote file we can say
sftp> get [remotefilename]
sftp> get [remotefilename] [local name]
uploading a file works the same way using the put
command
once we're done we use exit
or bye
to close out
setting up the host
You just have to make sure that the SSH server is running. On mac this is done by navigating tosystem preferences -> sharing
and checking the remote login box.
On windows you must install it from the optional features by navigating settings -> apps -> optional features
then select add a feature and select openssh client and server. I would then reccomend setting ssh server to run on startup by finding the process in task manager, right clicking it and managing its properties and selecting automatic start.
Now, to find the hostname on unix systems, you can simply use the $ hostname
command which will output the name of the computer on the local network. Since windows now has WSL you can do the same thing for windows machines.
what about if im not on the local network?
Well I have Tailscale set up on all my devices already so I plan to simply use that to tunnel into the local network and SSH from there. I assume there are more elegant options but for me this is the best solutions by occam's razor.