SSH technically works the same anywhere, but on Windows without special tooling, using SSH can be cumbersome as the CLI is not very… elegant? Generally, on Windows, people use tools like putty or MRemoteNG (also putty based) to make things neater.
If you’re on Linux, you can use SSH out of the box very cleanly by leveraging the config file to create named hosts.
For example, this verbose command:
ssh -i ~/.ssh/prod-key.pem firstname.lastname@example.org
Can be replaced by the following command – and the nice “pgadmin-prod” name even auto-completes. So, if you have 100 servers for different things, you can still find them easily.
This works if you add the following block into your ~/.ssh/config file.
- Host = the user-friendly name I want to use for this connection.
- User = the user I normally have to log in as.
- HostName = the IP address of the target host.
- IdentityFile = the path to the private key used for the connection.
You can have as many named hosts as you like and, again, their names will auto complete after the ssh command – so they’re very easy to use.
This gets even more effective if you combine it with a screen/session management app like tmux or screen. So, I recommend you look into those too if you don’t use them already (tmux is a little more modern if you’re a new to both).
I hope this helps you be a little more efficient, and thanks for reading.
If you need to use SSH or SCP with a different private key file, just specify it with -i. For example, to copy logs from a remote server using a specific private key file and user, do the following:
scp -i C:\Users\[your-user]\.ssh\pk_file [user]@[ip-addr]:/path/logs/* .
This -i will work regardless of OS, but the example is SSHing to a Linux server from a Windows server assuming you store your private keys in your user .ssh directory.
What is MRemoteNG?
MRemoteNG is a nice Windows OS tool for managing multiple SSH sessions (and session configurations) in one window – so you can log onto 10 servers and hop around trivially. It is built on top of Putty.
How Do You Use It With Azure VMs?
- When you create a VM in Azure, you give it a public key (assuming you didn’t use password authentication, which you should generally avoid).
- You can generate a key pair with PuTTYGen if you don’t have one (but then I’m assuming that you do have one if you already created the VM).
- Take the private key corresponding to that public key and save it into a file (it may already be in an “id_rsa” file in your .ssh directory in your user directory; e.g. C:\users\your-name\.ssh\id_rsa).
- Open PuTTYgen (it should come with MRemoteNG or Putty, otherwise you can get it yourself.
- Load the private key file.
- Click “Save private key” with Type = RSA selected (2048 bits is fine). It will save as a “PPK” file.
- Save it to your .ssh folder for consistency, or anywhere else – it really doesn’t matter much.
- Open MRemoteNG -> Tools -> Options -> Advanced -> Launch Putty -> Expand “SSH” -> Click Auth (Don’t expand) -> Put your PPK file path in “Private key file for authentication”.
- Click Session in putty and give the session a name in the “Saved Sessions” text box and then click Save. It should appear in the box below that.
- Now you have a saved session that can use this private key via a PPK file.
- Close Putty, make a new connection in MRemoteNG and select “Putty Session” = the new session you saved. It should be listed as an option.