Using PuTTY and SSH to manage your server
Create SSH key using PuTTYgen
- Open PuTTYgen app in your computer (you need to install PuTTY first).
- Click “Generate” button.
- Wave your mouse around in the window area until progress bar complete, this to generate a unique data.
- After it’s done, do not close the app yet.
- Open your DO Control Panel in browser and click “SSH Keys” link to visit SSH Keys Setting.
- Add “SSH Keys” and input key name (something like “my computer” or “my laptop”)
- Add “Public SSH Keys” you get from putty.
- “Create SSH Keys”, now you’ll get an SSH Keys you can use when creating your Droplet next time.
- Back to your PuTTY apps, and save “Public Key” and “Private Key” file (important).
Configure PuTTY session
- Open PuTTY app, and you’ll see “PuTTY Configuration” windows.
- Type in the “Host Name (or IP address)” field with the Droplet IP address from the welcome email, make sure the port number is “22”, and the connection type is “SSH”.
- Click PuTTY Config sidebar and click “Connection > SSH”, make sure it’s using “2” as “Preferred SSH protocol version”.
- Click “Session” from sidebar to go back to previous screen.
- In “Saved Session” field, input profile name, you can save it as “firstname.lastname@example.org”
- Click “Save” to save the “profile” so we can re-use this setting in the future.
- Click “Open” to start your PuTTY session.
- You’ll get a terminal window similar to Windows CMD/ Command Prompt
Login and use PuTTy
In “terminal” Window you’ll need to input your login as “root”
- login as: root
After that you need to input your root password (you get this in email after you create your droplet). While you type your password, your password will not visible, however it is still being entered as you type. Now you are loggin to your server.
If your SSH folder does not yet exist, create it manually using this command (one by one):
- mkdir ~/.ssh
- chmod 0700 ~/.ssh
- touch ~/.ssh/authorized_keys
- chmod 0644 ~/.ssh/authorized_keys
- mkdir is to create a directory
- chmod is to set file/folder permission
- touch is to create a file.
So from this commands, we are actually create a “.ssh” folder in our server, create a file “authorized_keys” and set it to the correct file permission.
Now, we need to edit this file and add our SSH Keys. Type this command:
- nano ~/.ssh/authorized_keys
nano is a terminal text/file editor. in this command we are editing the file “authorized_keys” using nano.
- Next step is to copy your “SSH Public Keys” from PuTTYgen to your clipboard.
- Go back to PuTTY terminal, using your mouse, “right-click” to the screen.
- This will “paste” your clipboard to PuTTY.
- Press “CTRL+x” to exit
- Press “y” to save changes.
- Press “Enter” to save the file.
- Type “reload ssh” command in terminal.
- Type “exit” to exit PuTTY session. (this will close the terminal)
How Copy-Paste in PuTTY works
- In Windows, we are used to “copy” using “CTRL+c” and using “CTRL+v” to paste. In PuTTY it works differently.
- To copy text from PuTTY, simply select it with your mouse, with no extra action, every time you select a text, it’s saved to your clipboard.
- To paste the text, simply use “right-click”/”middle click” of your mouse.
- You can also use keyboard “SHIFT+INS” to paste.
- You can copy-paste from PuTTY to other app such as text editor or browser.
Re-Configure PuTTY to use SSH Keys
After it’s done, we’ll re configure our PuTTY profile to use our SSH Keys so we don’t need to input our password every time we login to our server.
- Open PuTTY again.
- Select your saved profile. example: “email@example.com”
- Click “Load”
- Navigate to “Connection > Data” and input “root” in “Login details” / “Auto-login username:”, this to always use “root” user when using this saved session.
- Navigate to “Connection > SSH > Auth” and “browse” our “private key” file we saved previously using PuTTYgen.
- Navigate back to “Session” and “Save” our profile.
- Click “Open” to start session terminal.
- You are no longer asked for user name and password.
- type “exit” to exit PuTTY (if you want to close session).