Open za3ter2p opened 4 years ago
Oh wow. This got buried in my inbox and I'm literally not seeing it until just now. I'm going to find a way to add this SSH hardening stuff in, even though it's sort of a topic in-and-of-itself and other guides might consider it out of scope. Thanks very much for collating it. I'll make some time to review it as soon as possible and check it in.
Instructions here should be assumed I2P and SSH Server/Client already installed on user host and server, here will cover hardening ssh/sshd(server) and connect them to I2P.
Note: Instruction here is for most common free software used distro which is GNU/Linux Debian.
First lets start connecting using Keys (not passwords) and hardening SSH client before linking it to I2P:
Now generate new keys based on the best choice:
ssh-keygen -o -a 75 -t ed25519
It will ask you to enter passphrase , its better security to add it and to generate good one use KeePassXC. (you can leave it empty if you dont want to set it, just press enter)
Now copy the new generated public key to your server with the IP xxx.xxx.xxx.xxx (sometimes it will be name of the host , same thing replace the IP with the hostname)
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@xxx.xxx.xxx.xxx
It will ask you for the password , login normally and then your public key will be copied to your server.
Note: This is security practice to always use key authentication instead of using passwords which can be hammered by hackers.
Now logout from your server and lets harden your ssh client:
Erase ssh client default configurations: (you can copy/backup old configurations in case you want something or go back to it but mostly wont be needed)
echo "" | sudo tee /etc/ssh/ssh_config
Go to /etc/ssh/ssh_config (you can use any text editor here we gonna use nano)
sudo nano /etc/ssh/ssh_config
Copy/paste the following:
Ctrl+x then y then Enter to save and exit.
Now you can login to your server without the need to enter your password:
ssh user@xxx.xxx.xxx.xxx
(If it will ask you for a password , no problem we gonna configure sshd anyway)
Warnings before configuration
Configure sshd (openssh-server) to use the latest security:
Erase sshd default configurations:
echo "" | sudo tee /etc/ssh/sshd_config
Then go to /etc/ssh/sshd_config using nano text editor:
sudo nano /etc/ssh/sshd_config
Copy/paste:
Ctrl+x then y then Enter to save and exit.
Restart sshd:
sudo systemctl restart sshd
The ssh connection wont be interrupted and dont close it, Open another terminal (tab) and try to SSH to the server.
Connecting ssh/sshd To I2P:
Using java i2p's web interface, navigate to the (Links to your Router Console) Hidden Services Manager under "Global Tunnel Control" section press on "Tunnel Wizard"
Since you are setting up this tunnel for the SSH server, you need to select the "Server" tunnel.
You should fine-tune it later, but the Standard tunnel type is easiest to start with.
Give it a good description:
And tell it where the SSH server will be available.
(!) Choose any Port you prefer but it should be above 1024, in my instructions i used default 22.
Look over the results, and save your settings.
Advanced Settings
1- This is essential in case the server or the router restarted the tunnel shall start itself automatically 2- If you aren't that concerned about your anonymity, then you could reduce the number of hops you take. If you have trouble with speed, a higher tunnel count might help. A few backup tunnels are probably a good idea. You might have to dial-it-in a bit. 3- can be left as "Disable" which is the default or can be changed to "Blinded with look up password" 4- Make sure you are using the latest secure signature 5- Make sure you are using only the best secure encryption type 6- Optional!! (Leave it on Disable if you don't know how to use it) 7- Set it up for interactive connections instead of bulk connections. 8- If you choose to run a high number of tunnels then tick "Reduce on Idle" which will reduce the number of tunnels that run when the serve has experienced extended inactivity.
Same Thing: Using java i2p's web interface, navigate to the (Links to your Router Console) Hidden Services Manager under "Global Tunnel Control" section press on "Tunnel Wizard"
Since you are setting up this tunnel for the SSH client, you need to select the "client" tunnel.
Next, select the standard tunnel type. You will fine-tune this configuration later.
Give it a good description.
This is the only slightly tricky part. Go to the hidden services manager of the i2p router console and find the base64 "local destination" of the SSH server tunnel (not on the host/client but on the server side). You'll need to find a way to copy this information into the next step. I generally Tox it to myself, any off-the-record should be sufficient for most people.
Once you've found the base64 destination you want to connect to transmitted to your client device, then paste it into the client destination field.
Lastly, set a local port to connect your ssh client to. This will local port will be connected to the base64 destination and thus the SSH server.
Advanced:
1- Same thing explained for ssh server above 2- Same thing explained for ssh server above 3- This means once you want to connect to the SSH server over I2P a tunnel will be opened for that otherwise is off 4- Same thing explained for ssh server above 5- This will give always new keys for your identity (If you dont want that then dont enable it, but enable instead "Generate key to enable persistent client tunnel identity" under "Persistent private key", this is useful for ssh server whitelisting explain above in number 6) 6- Same thing explained for ssh server above
HowTo Whitelist only the client tunnel:
This is more-or-less optional, but it's pretty cool and will prevent anyone who happens to come across your destination from being able to tell you are hosting an SSH service.
First, retrieve the persistent client tunnel destination and transmit it to the server.
Add the client's base64 destination to the server's destination whitelist. Now you'll only be able to connect to the server tunnel from that specific client tunnel and no one else will be able to connect to that destination.
Mutual authentication FTW.