LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-12-2010, 01:06 PM   #1
dimm0k
Member
 
Registered: May 2008
Location: Brooklyn ZOO
Distribution: Slackware64 14.2
Posts: 564

Rep: Reputation: 56
securing machine before opening up SSH login


I'm currently using Slackware 13.0 and have my machine behind a Linksys DD-WRT router. I believe the DD-WRT software has all ports blocked by default so opening up my machine for SSH login would only leave my system vulnerable at that port. To give an extra layer of security for that opened port, I've created the following script that would be invoked as the users' shell.

#!/bin/sh
#if SSH_CLIENT defined run nail with $SSH_CLIENT as an argument
if [[ -n ${SSH_CLIENT} ]]; then
nail -r “me@email.com” -s “SSH login detected from $SSH_CLIENT” -S smtp=smtp.1and1.com -c me@email.com cellphone@carrier.com
fi
exec /bin/bash

This would hopefully send me an e-mail when someone logs in via SSH and then give the user the bash shell.

Anyone else care to share their tips and suggestions on securing this machine before I put it out there for SSH?
 
Old 05-12-2010, 01:53 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Sure:
1) Linux has iptables which is a system level firewall. You can lock down all the ports other than the ones you want. (Or more accurately deny everything and only open the ones you want.) That way if someone gets past your Switch/Router they still don't have access to Linux without hacking it as well.
In iptables you can even DROP packets from locations you don't want so if the IPs that were going to ssh in were fixed and few you could set rules to only allow those IPs in and DROP all others.
2) Stop all unnecessary processes. No point in having a bluetooth process running if you're not intending for bluetooth access.
3) Use an unusual port for ssh (that is don't use port 22) as all the script kiddies will try port 22.
4) You could implement SELinux which offers even further protections at file, process levels. (Many people don't do this but it is there.)

P.S. Careful about "!/bin/sh" - On some systems it is NOT linked to bash but to something else like tcsh, dash etc.... Best to use "!/bin/bash" if you intend the script be run by bash or "!/bin/dash" if you intend it to be run by dash.

Last edited by MensaWater; 05-12-2010 at 01:55 PM.
 
Old 05-12-2010, 02:01 PM   #3
dimm0k
Member
 
Registered: May 2008
Location: Brooklyn ZOO
Distribution: Slackware64 14.2
Posts: 564

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by MensaWater View Post
P.S. Careful about "!/bin/sh" - On some systems it is NOT linked to bash but to something else like tcsh, dash etc.... Best to use "!/bin/bash" if you intend the script be run by bash or "!/bin/dash" if you intend it to be run by dash.
Thanks for the above! I did have one question about what you said regrading "!/bin/sh". Are you saying on some systems /bin/sh is a soft link to /bin/tcsh or some other shell?
 
Old 05-12-2010, 07:39 PM   #4
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
Consider turning off passwords and using key based authentication instead. This will stop the dictionary type attacks. You should also disable root access (login) as an added precaution. It seems like a good percentage try to use root as the user name, so why even enable it.
 
Old 05-12-2010, 10:13 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try

ls -l /bin/sh

to see, but I'd never rely on a symlink; always specify the shell you really want.
 
Old 05-13-2010, 07:53 AM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by dimm0k View Post
Thanks for the above! I did have one question about what you said regrading "!/bin/sh". Are you saying on some systems /bin/sh is a soft link to /bin/tcsh or some other shell?
Yes.
 
Old 05-13-2010, 12:18 PM   #7
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
You might want to look into using AllowUsers and AllowHosts to restrict who and what IP addresses can use SSH. You also might consider a general file system integrity checker like Aide or Samhain.
 
Old 05-13-2010, 12:38 PM   #8
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello,

Here are some links that I've found when looking into the same, some time ago. Most likely you can put them to good use.
20 Linux Server Hardening Security Tips
Advanced SSH: security tips and tricks

Kind regards,

Eric
 
1 members found this post helpful.
Old 05-15-2010, 07:48 PM   #9
dimm0k
Member
 
Registered: May 2008
Location: Brooklyn ZOO
Distribution: Slackware64 14.2
Posts: 564

Original Poster
Rep: Reputation: 56
Thanks for all the suggestions and links guys!

While searching on ways to make my script work better, I found a post here http://forums.gentoo.org/viewtopic-t...5-start-0.html where the OP mentioned using /etc/ssh/sshrc. Would that be a better solution overall or would a script like what I have in my original post do the same?

Last edited by dimm0k; 05-15-2010 at 11:43 PM.
 
Old 05-16-2010, 03:42 AM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
While an email or pager alert is a "nice to have" in terms of security posture it certainly isn't a "must have". I'm saying that because while under the current scenario (and the assumptions you attach to the current state) everything seems happily uninteresting you should care what for example happens if: 0) the DD-WRT gets compromised or 1) if its configuration gets changed to allow full access, 2) when a user cracks wide open your SSHd setup or 3) a (seemingly) legitimate user performs certain tasks on your system, 4) you later on enable other services. In short what you should look for first are system hardening best practices and not focus on SSH alone. And please get rid of that misconception that your script would "give an extra layer of security" as it does not. It's only an after-the-fact alert and does not harden your SSH setup or keep users from trying (repeatedly).

For system hardening see your slackware documentation and http://www.linuxquestions.org/questi...erences-45261/ (and please do test after hardening) and for SSH security see the sticky http://www.linuxquestions.org/questi...tempts-340366/ thread where advice for securing SSH was posted ages ago.
 
Old 05-16-2010, 02:17 PM   #11
dimm0k
Member
 
Registered: May 2008
Location: Brooklyn ZOO
Distribution: Slackware64 14.2
Posts: 564

Original Poster
Rep: Reputation: 56
I understand unSpawn, however because I am the only one that has access to this system, an e-mail notification would at least give me an indication of whether or not the person logging in was me or not.

With my current setup of using the above posted script, ssh into the box works, however scp does not. Does anyone have any suggestions on fixing that?
 
  


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
how to transfer ssh login attempts to linux machine junust Linux - Software 5 07-22-2008 09:13 AM
passwordless login on the same machine via ssh athreyavc Linux - Server 2 06-20-2008 12:12 AM
machine not allowing login thru virtual console, only thru ssh dsids Linux - Newbie 2 01-15-2007 11:46 AM
SSH remote login fails after moving virtual machine novice_mage Linux - Networking 7 12-31-2006 06:53 AM
can't login to a Slack machine using a NIS account through ssh nIMBVS Slackware 2 07-15-2004 02:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:53 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