LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-01-2024, 11:46 AM   #1
Jason.nix
Member
 
Registered: Feb 2023
Posts: 561

Rep: Reputation: 10
Post Restrict SSH based on MAC address


Hello,
I guess there is no way to limit SSH based on MAC address. I want to connect to a server through SSH protocol on the mobile phone, but the IP address of the mobile phone is dynamic, and on the other hand, I can't open SSH on all IP addresses. What's the solution?

Thank you.
 
Old 02-01-2024, 11:52 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,310
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
I'm not sure what problem you are trying to solve.

If you are worried about people bruteforcing passwords, require an SSH key first before the password:

Code:
AuthenticationMethods publickey,password
If connections via the LAN are to be exempted from the 2FA then use a Match clause.


Or you could instead just go with keys only and turn off passwords completely.
 
3 members found this post helpful.
Old 02-01-2024, 12:35 PM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
I don't understand. I guess phone is the client where do you want to connect to a server from. But probably you need something else.
Can you give us more details?
McAddress is not directly visible, but I think there is a plugin which can be used. The problem is that MAC address can be changed in some cases, you cannot rely on it.
 
Old 02-01-2024, 04:25 PM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
In addition to what @Turbocapitalist suggests, you could have SSH listening on a non-standard port and use firewall rules to only pass traffic from the address space used by the mobile phone provider.
 
Old 02-01-2024, 05:14 PM   #5
rkelsen
Senior Member
 
Registered: Sep 2004
Distribution: slackware
Posts: 4,448
Blog Entries: 7

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
Quote:
Originally Posted by Jason.nix View Post
I guess there is no way to limit SSH based on MAC address. I want to connect to a server through SSH protocol on the mobile phone, but the IP address of the mobile phone is dynamic, and on the other hand, I can't open SSH on all IP addresses. What's the solution?
You're asking lots of interesting questions here!

The problem with MAC filters is that it is very easy to spoof MAC addresses.

This is probably something you've heard before, BUT, my solution to this would be to use OpenVPN on a high/non-standard port. There is a client app for it on Android and IOS. Then use ConnectBot or similar app on the phone to SSH in.

There are people on here who might disagree with me, but IMO, opening your SSH port to the internet is asking for trouble.
 
Old 02-04-2024, 01:30 PM   #6
jayjwa
Member
 
Registered: Jul 2003
Location: NY
Distribution: Slackware, Termux
Posts: 777

Rep: Reputation: 244Reputation: 244Reputation: 244
The mobile will be from a set prefix, even if dynamic. Limit from that range. Key-only SSH login on a non-standard port is really all you need unless you are going up against the top agents of the NSA who have zero-days that we don't know about.
 
Old 02-05-2024, 01:08 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
if you want to be really [paranoid] sure you need to install a special software on the given host which can confirm the identity of the device. But I still do not understand what do you want to solve here.
 
Old 02-08-2024, 03:40 PM   #8
Jason.nix
Member
 
Registered: Feb 2023
Posts: 561

Original Poster
Rep: Reputation: 10
Hello,
Thank you so much for all replies.
What is your opinion about using iptables:
Code:
# iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source "MAC Address" -j ACCEPT
 
Old 02-08-2024, 08:09 PM   #9
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Mobile devices may randomise the MAC address when connecting to different networks as a security and anti-tracking measure. Your setup, your decision.
 
Old 02-09-2024, 03:24 AM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,310
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Quote:
Originally Posted by Jason.nix View Post
What is your opinion about using iptables:


Code:
nft add rule inet filter input tcp dport 22 ether saddr 00:0f:54:0c:11:04 accept
MAC addresses can be spoofed trivially, some systems even randomize theirs. Such a filter would only work for systems connecting from the same LAN, anyway.

So not much with trying MAC address filtering unless you have a specific use-case in mind, one which actually suits tracking the MAC address.

If you're looking for a second factor for authentication, requiring both an SSH key and a password would be the easiest way.
 
1 members found this post helpful.
Old 02-09-2024, 07:02 AM   #11
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
If the issue is "I can't open SSH on all IP addresses" then an alternative technique is to have the server initiate the connection and establish a reverse SSH tunnel.
This would require:
1. Maintaining a dynamic IP address for the mobile phone.
2. Being able to manipulate ports on the server that require root privileges.

I used to do this with a script run from cron.
 
Old 02-12-2024, 10:55 AM   #12
Jason.nix
Member
 
Registered: Feb 2023
Posts: 561

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by Turbocapitalist View Post


Code:
nft add rule inet filter input tcp dport 22 ether saddr 00:0f:54:0c:11:04 accept
MAC addresses can be spoofed trivially, some systems even randomize theirs. Such a filter would only work for systems connecting from the same LAN, anyway.

So not much with trying MAC address filtering unless you have a specific use-case in mind, one which actually suits tracking the MAC address.

If you're looking for a second factor for authentication, requiring both an SSH key and a password would be the easiest way.
Hello,
Thank you so much for your reply.
How can I make it possible to create only one session from each MAC address? Maybe this can prevent mac address cloning to some extent.
 
Old 02-12-2024, 11:03 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Quote:
Originally Posted by Jason.nix View Post
Hello,
Thank you so much for your reply.
How can I make it possible to create only one session from each MAC address? Maybe this can prevent mac address cloning to some extent.
I'm afraid, no. One given MAC address can only be used only once in a network, so mac address cloning is pointless. But using a random address is possible and you cannot create a filter for that.
 
Old 02-17-2024, 07:00 AM   #14
Jason.nix
Member
 
Registered: Feb 2023
Posts: 561

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by pan64 View Post
I'm afraid, no. One given MAC address can only be used only once in a network, so mac address cloning is pointless. But using a random address is possible and you cannot create a filter for that.
Hello,
Thanks again.
Does this only apply to iptables? Random MAC addresses are useless when only you allow specific MAC addresses to connect.

Last edited by Jason.nix; 02-17-2024 at 07:02 AM.
 
  


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
Change mac address to multicast mac address ubuntuv Linux - Networking 5 01-16-2019 07:21 AM
how do I find what MAC address web pages see as my MAC address rob.rice General 20 05-29-2010 02:08 AM
[SOLVED] IPTABLES: Restrict Internet access based on time of day and MAC address ScottSmith Linux - Security 7 02-09-2010 02:25 AM
Ethernet MAC Addresses database; MAC address-based processing cctualatin Linux - Newbie 1 04-14-2009 08:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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