LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-19-2015, 03:14 PM   #1
moog7
LQ Newbie
 
Registered: Mar 2013
Posts: 12

Rep: Reputation: Disabled
Securing SSH


What's the best way of securing SSH access when on a dynamic IP address?
 
Old 10-19-2015, 06:35 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I am aware of password, keypair or certificate. What's best depends on your situation. Personally I'd go for keys protected with passphrases and managed with ssh-agent or keychain, as setting up a CA is too much pain for me.
This should be the same whether you use dynamic or static addresses. Or am I missing something?

Edit: Of course there is the little problem of client and server knowing each other by IP address, so my answer doesn't address your problem. It seems though that you are not the first person with this question; googling will help.

Last edited by berndbausch; 10-19-2015 at 06:41 PM.
 
Old 10-19-2015, 06:51 PM   #3
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
This might be helpful

http://www.linuxquestions.org/questi...ts-4175530596/
 
Old 10-20-2015, 10:53 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Buy a static one if you have such an option.
$5.00 USD in the USA. YCMV
 
Old 10-21-2015, 03:41 PM   #5
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Rep: Reputation: 54
Quote:
Originally Posted by Habitual View Post
Buy a static one if you have such an option.
$5.00 USD in the USA. YCMV
Not all ISPs provide statics. Mine does not, and it's a pain because their DHCP lease time is 10 minutes. You just need to look at the router funny and you get a new IP.

What I would do is put SSH on a non default port, that will stop all the bots from flooding your log files, then install fail2ban. That blocks IPs that fail to login too many times. I set it to 3. You could also try to find out what your ISP's IP ranges are and then only allow for those ranges, it will at least minimize the amount of attack sources. TBH I don't bother though I just have it wide open to any IP but use fail2ban. By having it on a non default port I've never even had fail2ban hit. I have it setup to alert me if it happens.
 
Old 10-22-2015, 04:11 PM   #6
moog7
LQ Newbie
 
Registered: Mar 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Red Squirrel View Post
Not all ISPs provide statics. Mine does not, and it's a pain because their DHCP lease time is 10 minutes. You just need to look at the router funny and you get a new IP.

What I would do is put SSH on a non default port, that will stop all the bots from flooding your log files, then install fail2ban. That blocks IPs that fail to login too many times. I set it to 3. You could also try to find out what your ISP's IP ranges are and then only allow for those ranges, it will at least minimize the amount of attack sources. TBH I don't bother though I just have it wide open to any IP but use fail2ban. By having it on a non default port I've never even had fail2ban hit. I have it setup to alert me if it happens.
Thank you. That was my thinking too, I thought about limiting to my ISP's IP range (better than nothing) and with fail2ban running but wanted to see if there were better ways of securing it.

Do you get many log in attempts?

Thanks
 
Old 10-22-2015, 05:58 PM   #7
maples
Member
 
Registered: Oct 2013
Location: IN, USA
Distribution: Arch, Debian Jessie
Posts: 814

Rep: Reputation: 265Reputation: 265Reputation: 265
Quote:
Originally Posted by moog7 View Post
Thank you. That was my thinking too, I thought about limiting to my ISP's IP range (better than nothing) and with fail2ban running but wanted to see if there were better ways of securing it.

Do you get many log in attempts?

Thanks
I agree with Red Squirrel, run it on something other than 22. I do that with my home server, and I don't think I've ever had a single unauthorized login attempt.

However, this should NOT be the only step you take in securing SSH. Many people (including myself) would call this "security by obscurity"- which should never be considered a real security feature. https://en.wikipedia.org/wiki/Security_by_obscurity I view it as simply a method of keeping my logs clean.

Look into using SSH keys and disabling root login.
 
Old 10-22-2015, 08:11 PM   #8
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Rep: Reputation: 54
I don't get any attempts with it on a different port at least none that try more than 3 times. I test it occasionally to make sure my alerting works (just did it now actually since I thought of it. :P )

http://gal.redsquirrel.me/thumbs/lrg-3160-1__4_.png

I also get an alert on my phone.

But yeah don't rely on a different port only as it wont stop a targeted attack, it will just stop you from getting a million alerts all the time.

One time I put a SSH server online on the default port and I had not gotten around to installing fail2ban yet, and it was hacked within 10 minutes. Brute force is not a matter of if but a matter of when. By the time I noticed why my internet was so slow I found that the machine got hacked, and the bot had already hacked 3 other online machines from mine. They basically spread like a worm. The bot was nice enough to leave a log behind. :P It was kinda neat to see it happen actually, it was a test VM so nothing was really compromised. Though it technically could have been used to hack my internal network, so definitely be careful if you decide to try anything like this and do it on a separate vlan. I did not know any better at that time.

Last edited by Red Squirrel; 10-22-2015 at 08:20 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Securing SSH jonnybinthemix Linux - Newbie 3 06-04-2014 06:00 AM
[SOLVED] securing ssh logins dinakumar12 Linux - Server 2 09-15-2010 01:40 AM
Securing SSH ZilverZtream Linux - Security 5 12-10-2004 03:33 PM
securing ssh robberttheman Linux - Security 8 08-27-2004 07:36 AM
Securing SSH tarballedtux Linux - Security 3 11-16-2002 04:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration