SSH Keys and Server Access¶
What are SSH Keys?¶
SSH keys are a secure way to log in to another computer or server without using a password. Instead, you use a pair of cryptographic keys:
- Private Key: Stored safely on your computer (never shared).
- Public Key: Shared with the remote machine (placed in
~/.ssh/authorized_keys).
Think of the public key as a lock and the private key as the only key that opens it.
How SSH Access Works¶
(a) Generate a key pair on your system:
This creates:
id_rsa→ Your private key (keep this safe)id_rsa.pub→ Your public key (you can share this)
These above keys are stored in :
C:\Users\<YourUsername>\.ssh(on windows)~/.ssh/(on linux)
You can run following cmd:
ls -la ~/.ssh(lists all files, including hidden ones with detailed info like file permissions, etc)cat ~/.ssh/id_ed25519.pub(To view your public key (example for Ed25519):)
Copy your public key to the remote system:
(b) SSH into the remote machine:
(i) Enable OpenSSH Server on the Windows machine. [ Go to Settings > Apps > Optional Features ]
-
If OpenSSH Server is not installed, click Add a feature and install OpenSSH Server
-
Then start it:
(ii) Now create authorized_keys file in .ssh folder
echo your-public-key >> ~/.ssh/authorized_keys #(for linux)
notepad C:\Users\<RemoteUsername>\.ssh\authorized_keys #(for windows)
Put the authorized_keys file in either of:
-
C:\Users\
.ssh\authorized_keys (user-level login) -
C:\ProgramData\ssh\administrators_authorized_keys (for admin-level access)
(iii) Make sure the .ssh folder and authorized_keys file have the right permissions:
(iv) Restart-Service sshd (optional) :
(v) SSH into the Windows machine (from your local machine)
How to Find Someone’s IP (Example Idea)¶
You can serve a local website using:
Ask the person to open the link. When they visit it, you’ll capture their IP — which you can then use to attempt SSH (if their system is configured to allow it).
Examples¶
DigitalOcean Droplet¶
If you created a Droplet (virtual server) on DigitalOcean with SSH access:
Your public key will be in:
To check:
EC2 Instance (AWS)¶
While setting up a server on aws you can create the ssh key-pair for a particular user and then can download it and
(i) Run this command (if you have choosen ubuntu machine)
where this - i : input keypair rajat.pem which should be in root folder i.e. /users/
(ii) Change rajat.pem file access mode (permissions)
- Check the permission of file using:
- Run below command to change permissions:
Real-World Example: GitHub¶
- Add your public key to your GitHub account.
- When you
git clonea private repo, GitHub checks if your private key matches the stored public key. - If yes, access is granted — no password needed!
Virtual Machines (Cloud Servers)¶
Platforms like:
- DigitalOcean: Droplets
- AWS: EC2 Instances
...are just virtual Linux machines in the cloud. You can log into them via SSH using the steps above.