Don't allow users to SSH to other systems
I know how to restrict SSH access to a system. How can I restrict SSH access to ANOTHER system when a user has logged in to my system. For example:
# ssh joe@myserver
# joe@myserver $ /home/joe
# joe@myserver $ /home/joe ssh joe@anotherserver
# BLOCK THIS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I'm looking at IPTables now but I'm not sure of the implications of blocking outgoing port 22.
linux ssh iptables
|
show 2 more comments
I know how to restrict SSH access to a system. How can I restrict SSH access to ANOTHER system when a user has logged in to my system. For example:
# ssh joe@myserver
# joe@myserver $ /home/joe
# joe@myserver $ /home/joe ssh joe@anotherserver
# BLOCK THIS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I'm looking at IPTables now but I'm not sure of the implications of blocking outgoing port 22.
linux ssh iptables
If the user don't have admin right, maybe restrict the ssh command into the /usr/sbin ? So only those with sudo access can ssh out?
– Darius
Feb 26 at 20:43
1
Similar questions : unix.stackexchange.com/questions/472554/… serverfault.com/questions/660880/…
– Christopher Hostage
Feb 26 at 20:44
3
@Darius presumably the user could provide their own ssh program
– emory
Feb 26 at 20:45
The Server Fault link that @ChristopherHostage provided seems to be exactly what you want/need; if cross-site "duplicates" were permissible flags, I'd be flagging this question as a dupe of it.
– Jeff Zeitlin
Feb 26 at 20:54
3
They could also SSH out to a custom port, like 80, if the 22 is blocked. It really depends on what the scenario is here. Why are you trying to do this, Ken? What systems are they SSHing to that you want to block? Are they internal? Or something custom across the internet?
– HackSlash
Feb 26 at 22:28
|
show 2 more comments
I know how to restrict SSH access to a system. How can I restrict SSH access to ANOTHER system when a user has logged in to my system. For example:
# ssh joe@myserver
# joe@myserver $ /home/joe
# joe@myserver $ /home/joe ssh joe@anotherserver
# BLOCK THIS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I'm looking at IPTables now but I'm not sure of the implications of blocking outgoing port 22.
linux ssh iptables
I know how to restrict SSH access to a system. How can I restrict SSH access to ANOTHER system when a user has logged in to my system. For example:
# ssh joe@myserver
# joe@myserver $ /home/joe
# joe@myserver $ /home/joe ssh joe@anotherserver
# BLOCK THIS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I'm looking at IPTables now but I'm not sure of the implications of blocking outgoing port 22.
linux ssh iptables
linux ssh iptables
asked Feb 26 at 20:38
Ken JKen J
61
61
If the user don't have admin right, maybe restrict the ssh command into the /usr/sbin ? So only those with sudo access can ssh out?
– Darius
Feb 26 at 20:43
1
Similar questions : unix.stackexchange.com/questions/472554/… serverfault.com/questions/660880/…
– Christopher Hostage
Feb 26 at 20:44
3
@Darius presumably the user could provide their own ssh program
– emory
Feb 26 at 20:45
The Server Fault link that @ChristopherHostage provided seems to be exactly what you want/need; if cross-site "duplicates" were permissible flags, I'd be flagging this question as a dupe of it.
– Jeff Zeitlin
Feb 26 at 20:54
3
They could also SSH out to a custom port, like 80, if the 22 is blocked. It really depends on what the scenario is here. Why are you trying to do this, Ken? What systems are they SSHing to that you want to block? Are they internal? Or something custom across the internet?
– HackSlash
Feb 26 at 22:28
|
show 2 more comments
If the user don't have admin right, maybe restrict the ssh command into the /usr/sbin ? So only those with sudo access can ssh out?
– Darius
Feb 26 at 20:43
1
Similar questions : unix.stackexchange.com/questions/472554/… serverfault.com/questions/660880/…
– Christopher Hostage
Feb 26 at 20:44
3
@Darius presumably the user could provide their own ssh program
– emory
Feb 26 at 20:45
The Server Fault link that @ChristopherHostage provided seems to be exactly what you want/need; if cross-site "duplicates" were permissible flags, I'd be flagging this question as a dupe of it.
– Jeff Zeitlin
Feb 26 at 20:54
3
They could also SSH out to a custom port, like 80, if the 22 is blocked. It really depends on what the scenario is here. Why are you trying to do this, Ken? What systems are they SSHing to that you want to block? Are they internal? Or something custom across the internet?
– HackSlash
Feb 26 at 22:28
If the user don't have admin right, maybe restrict the ssh command into the /usr/sbin ? So only those with sudo access can ssh out?
– Darius
Feb 26 at 20:43
If the user don't have admin right, maybe restrict the ssh command into the /usr/sbin ? So only those with sudo access can ssh out?
– Darius
Feb 26 at 20:43
1
1
Similar questions : unix.stackexchange.com/questions/472554/… serverfault.com/questions/660880/…
– Christopher Hostage
Feb 26 at 20:44
Similar questions : unix.stackexchange.com/questions/472554/… serverfault.com/questions/660880/…
– Christopher Hostage
Feb 26 at 20:44
3
3
@Darius presumably the user could provide their own ssh program
– emory
Feb 26 at 20:45
@Darius presumably the user could provide their own ssh program
– emory
Feb 26 at 20:45
The Server Fault link that @ChristopherHostage provided seems to be exactly what you want/need; if cross-site "duplicates" were permissible flags, I'd be flagging this question as a dupe of it.
– Jeff Zeitlin
Feb 26 at 20:54
The Server Fault link that @ChristopherHostage provided seems to be exactly what you want/need; if cross-site "duplicates" were permissible flags, I'd be flagging this question as a dupe of it.
– Jeff Zeitlin
Feb 26 at 20:54
3
3
They could also SSH out to a custom port, like 80, if the 22 is blocked. It really depends on what the scenario is here. Why are you trying to do this, Ken? What systems are they SSHing to that you want to block? Are they internal? Or something custom across the internet?
– HackSlash
Feb 26 at 22:28
They could also SSH out to a custom port, like 80, if the 22 is blocked. It really depends on what the scenario is here. Why are you trying to do this, Ken? What systems are they SSHing to that you want to block? Are they internal? Or something custom across the internet?
– HackSlash
Feb 26 at 22:28
|
show 2 more comments
3 Answers
3
active
oldest
votes
You should OK to block outgoing SSH if you don't need it for anything. Blocking outgoing requests on port 22 will not block incoming requests (because blocking is done on the destination port, which is different to the source port).
I've not played around with it much, but on some versions of iptables it should also be possible to block connections based on the userid, with a command like
iptables -I INPUT -p tcp --dport 22 -m owner -uid XXX -j DROP
To find the uid, you can look in the password file, with a command like
grep "username" /etc/passwd | cut -f3 -d":"
Why was this downvoted?
– davidgo
Feb 27 at 7:55
add a comment |
You have a different option in centos 6 and Centos 7
Many of us use TCP wrapper
, iptables
and firewalld
TCP wrapper Example
/etc/hosts.allow
sshd : IP-Address
Iptables Example
iptables -I INPUT -s x.x.x.x --dport 22 -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport 22 -j ACCEPT
IPTABLES -A INPUT --dport 22 -j DROP
IPTABLES -A OUTPUT --sport 22 -j DROP
then run below command
service iptables save
Firewalld Example
systemctl start firewalld.service
systemctl enable firewalld.service
firewall-cmd –zone=”trusted” –add-source=<external IP 1>
firewall-cmd –zone=”trusted” –add-source=<external IP 1> –permanent
firewall-cmd –zone=”trusted” –add-source=<external IP 2>
firewall-cmd –zone=”trusted” –add-source=<external IP 2> –permanent
firewall-cmd –zone=”trusted” –add-service=ssh
firewall-cmd –zone=”trusted” –add-service=ssh –permanent
firewall-cmd –zone=”trusted” –list-all
firewall-cmd –zone=public –remove-service=ssh
firewall-cmd –zone=public –remove-service=ssh –permanent
add a comment |
You can block all SSH communication
through iptables
and allow for particular IP ADDRESS.
In below example,
First two rule is to allow for particular IP Address.
x.x.x.x - Your system IP
Last two rules, will block SSH connection for all IP address.
iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
2
Note that this doesn't block "SSH communication", it just blocks port 22. If I was a user restricted this way, I'd just run an sshd server on port, say, 2222, on the target machine, and then I'd happily connect to it from the source machine with those iptables rules. As mentioned in the comments to this question, first you need to define the scenario.
– dirkt
Feb 27 at 6:44
For that, If your SSH port changes, Use ssh instead of 22. It means if you will change ssh port it will get it from socket example - "2222" . It will block and allow as per iptables rules when your ssh port changes.iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
– bhupender singh
Feb 27 at 6:51
It's not that "the ssh port changes". It's that the user you want to block from using ssh can easily do that by picking some other port you (the admin) have not already blocked. So you can block ports all day long, and keeping adding ports to it, the user you want to block will just switch to a different port. And you can't block all ports...
– dirkt
Feb 27 at 6:54
i edited my answer, i just choose ssh instead of 22. it will automatically take ssh port from socket.
– bhupender singh
Feb 27 at 6:57
1
No, it won't. It will look upssh
in/etc/services
and take the port number from there, which is 22. There is no "ssh port on a socket". And you haven't understood anything of what I was trying to explain.
– dirkt
Feb 27 at 7:10
|
show 2 more comments
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1409687%2fdont-allow-users-to-ssh-to-other-systems%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should OK to block outgoing SSH if you don't need it for anything. Blocking outgoing requests on port 22 will not block incoming requests (because blocking is done on the destination port, which is different to the source port).
I've not played around with it much, but on some versions of iptables it should also be possible to block connections based on the userid, with a command like
iptables -I INPUT -p tcp --dport 22 -m owner -uid XXX -j DROP
To find the uid, you can look in the password file, with a command like
grep "username" /etc/passwd | cut -f3 -d":"
Why was this downvoted?
– davidgo
Feb 27 at 7:55
add a comment |
You should OK to block outgoing SSH if you don't need it for anything. Blocking outgoing requests on port 22 will not block incoming requests (because blocking is done on the destination port, which is different to the source port).
I've not played around with it much, but on some versions of iptables it should also be possible to block connections based on the userid, with a command like
iptables -I INPUT -p tcp --dport 22 -m owner -uid XXX -j DROP
To find the uid, you can look in the password file, with a command like
grep "username" /etc/passwd | cut -f3 -d":"
Why was this downvoted?
– davidgo
Feb 27 at 7:55
add a comment |
You should OK to block outgoing SSH if you don't need it for anything. Blocking outgoing requests on port 22 will not block incoming requests (because blocking is done on the destination port, which is different to the source port).
I've not played around with it much, but on some versions of iptables it should also be possible to block connections based on the userid, with a command like
iptables -I INPUT -p tcp --dport 22 -m owner -uid XXX -j DROP
To find the uid, you can look in the password file, with a command like
grep "username" /etc/passwd | cut -f3 -d":"
You should OK to block outgoing SSH if you don't need it for anything. Blocking outgoing requests on port 22 will not block incoming requests (because blocking is done on the destination port, which is different to the source port).
I've not played around with it much, but on some versions of iptables it should also be possible to block connections based on the userid, with a command like
iptables -I INPUT -p tcp --dport 22 -m owner -uid XXX -j DROP
To find the uid, you can look in the password file, with a command like
grep "username" /etc/passwd | cut -f3 -d":"
answered Feb 27 at 3:38
davidgodavidgo
44.6k75292
44.6k75292
Why was this downvoted?
– davidgo
Feb 27 at 7:55
add a comment |
Why was this downvoted?
– davidgo
Feb 27 at 7:55
Why was this downvoted?
– davidgo
Feb 27 at 7:55
Why was this downvoted?
– davidgo
Feb 27 at 7:55
add a comment |
You have a different option in centos 6 and Centos 7
Many of us use TCP wrapper
, iptables
and firewalld
TCP wrapper Example
/etc/hosts.allow
sshd : IP-Address
Iptables Example
iptables -I INPUT -s x.x.x.x --dport 22 -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport 22 -j ACCEPT
IPTABLES -A INPUT --dport 22 -j DROP
IPTABLES -A OUTPUT --sport 22 -j DROP
then run below command
service iptables save
Firewalld Example
systemctl start firewalld.service
systemctl enable firewalld.service
firewall-cmd –zone=”trusted” –add-source=<external IP 1>
firewall-cmd –zone=”trusted” –add-source=<external IP 1> –permanent
firewall-cmd –zone=”trusted” –add-source=<external IP 2>
firewall-cmd –zone=”trusted” –add-source=<external IP 2> –permanent
firewall-cmd –zone=”trusted” –add-service=ssh
firewall-cmd –zone=”trusted” –add-service=ssh –permanent
firewall-cmd –zone=”trusted” –list-all
firewall-cmd –zone=public –remove-service=ssh
firewall-cmd –zone=public –remove-service=ssh –permanent
add a comment |
You have a different option in centos 6 and Centos 7
Many of us use TCP wrapper
, iptables
and firewalld
TCP wrapper Example
/etc/hosts.allow
sshd : IP-Address
Iptables Example
iptables -I INPUT -s x.x.x.x --dport 22 -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport 22 -j ACCEPT
IPTABLES -A INPUT --dport 22 -j DROP
IPTABLES -A OUTPUT --sport 22 -j DROP
then run below command
service iptables save
Firewalld Example
systemctl start firewalld.service
systemctl enable firewalld.service
firewall-cmd –zone=”trusted” –add-source=<external IP 1>
firewall-cmd –zone=”trusted” –add-source=<external IP 1> –permanent
firewall-cmd –zone=”trusted” –add-source=<external IP 2>
firewall-cmd –zone=”trusted” –add-source=<external IP 2> –permanent
firewall-cmd –zone=”trusted” –add-service=ssh
firewall-cmd –zone=”trusted” –add-service=ssh –permanent
firewall-cmd –zone=”trusted” –list-all
firewall-cmd –zone=public –remove-service=ssh
firewall-cmd –zone=public –remove-service=ssh –permanent
add a comment |
You have a different option in centos 6 and Centos 7
Many of us use TCP wrapper
, iptables
and firewalld
TCP wrapper Example
/etc/hosts.allow
sshd : IP-Address
Iptables Example
iptables -I INPUT -s x.x.x.x --dport 22 -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport 22 -j ACCEPT
IPTABLES -A INPUT --dport 22 -j DROP
IPTABLES -A OUTPUT --sport 22 -j DROP
then run below command
service iptables save
Firewalld Example
systemctl start firewalld.service
systemctl enable firewalld.service
firewall-cmd –zone=”trusted” –add-source=<external IP 1>
firewall-cmd –zone=”trusted” –add-source=<external IP 1> –permanent
firewall-cmd –zone=”trusted” –add-source=<external IP 2>
firewall-cmd –zone=”trusted” –add-source=<external IP 2> –permanent
firewall-cmd –zone=”trusted” –add-service=ssh
firewall-cmd –zone=”trusted” –add-service=ssh –permanent
firewall-cmd –zone=”trusted” –list-all
firewall-cmd –zone=public –remove-service=ssh
firewall-cmd –zone=public –remove-service=ssh –permanent
You have a different option in centos 6 and Centos 7
Many of us use TCP wrapper
, iptables
and firewalld
TCP wrapper Example
/etc/hosts.allow
sshd : IP-Address
Iptables Example
iptables -I INPUT -s x.x.x.x --dport 22 -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport 22 -j ACCEPT
IPTABLES -A INPUT --dport 22 -j DROP
IPTABLES -A OUTPUT --sport 22 -j DROP
then run below command
service iptables save
Firewalld Example
systemctl start firewalld.service
systemctl enable firewalld.service
firewall-cmd –zone=”trusted” –add-source=<external IP 1>
firewall-cmd –zone=”trusted” –add-source=<external IP 1> –permanent
firewall-cmd –zone=”trusted” –add-source=<external IP 2>
firewall-cmd –zone=”trusted” –add-source=<external IP 2> –permanent
firewall-cmd –zone=”trusted” –add-service=ssh
firewall-cmd –zone=”trusted” –add-service=ssh –permanent
firewall-cmd –zone=”trusted” –list-all
firewall-cmd –zone=public –remove-service=ssh
firewall-cmd –zone=public –remove-service=ssh –permanent
answered Feb 27 at 6:17
Aman ShuklaAman Shukla
1
1
add a comment |
add a comment |
You can block all SSH communication
through iptables
and allow for particular IP ADDRESS.
In below example,
First two rule is to allow for particular IP Address.
x.x.x.x - Your system IP
Last two rules, will block SSH connection for all IP address.
iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
2
Note that this doesn't block "SSH communication", it just blocks port 22. If I was a user restricted this way, I'd just run an sshd server on port, say, 2222, on the target machine, and then I'd happily connect to it from the source machine with those iptables rules. As mentioned in the comments to this question, first you need to define the scenario.
– dirkt
Feb 27 at 6:44
For that, If your SSH port changes, Use ssh instead of 22. It means if you will change ssh port it will get it from socket example - "2222" . It will block and allow as per iptables rules when your ssh port changes.iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
– bhupender singh
Feb 27 at 6:51
It's not that "the ssh port changes". It's that the user you want to block from using ssh can easily do that by picking some other port you (the admin) have not already blocked. So you can block ports all day long, and keeping adding ports to it, the user you want to block will just switch to a different port. And you can't block all ports...
– dirkt
Feb 27 at 6:54
i edited my answer, i just choose ssh instead of 22. it will automatically take ssh port from socket.
– bhupender singh
Feb 27 at 6:57
1
No, it won't. It will look upssh
in/etc/services
and take the port number from there, which is 22. There is no "ssh port on a socket". And you haven't understood anything of what I was trying to explain.
– dirkt
Feb 27 at 7:10
|
show 2 more comments
You can block all SSH communication
through iptables
and allow for particular IP ADDRESS.
In below example,
First two rule is to allow for particular IP Address.
x.x.x.x - Your system IP
Last two rules, will block SSH connection for all IP address.
iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
2
Note that this doesn't block "SSH communication", it just blocks port 22. If I was a user restricted this way, I'd just run an sshd server on port, say, 2222, on the target machine, and then I'd happily connect to it from the source machine with those iptables rules. As mentioned in the comments to this question, first you need to define the scenario.
– dirkt
Feb 27 at 6:44
For that, If your SSH port changes, Use ssh instead of 22. It means if you will change ssh port it will get it from socket example - "2222" . It will block and allow as per iptables rules when your ssh port changes.iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
– bhupender singh
Feb 27 at 6:51
It's not that "the ssh port changes". It's that the user you want to block from using ssh can easily do that by picking some other port you (the admin) have not already blocked. So you can block ports all day long, and keeping adding ports to it, the user you want to block will just switch to a different port. And you can't block all ports...
– dirkt
Feb 27 at 6:54
i edited my answer, i just choose ssh instead of 22. it will automatically take ssh port from socket.
– bhupender singh
Feb 27 at 6:57
1
No, it won't. It will look upssh
in/etc/services
and take the port number from there, which is 22. There is no "ssh port on a socket". And you haven't understood anything of what I was trying to explain.
– dirkt
Feb 27 at 7:10
|
show 2 more comments
You can block all SSH communication
through iptables
and allow for particular IP ADDRESS.
In below example,
First two rule is to allow for particular IP Address.
x.x.x.x - Your system IP
Last two rules, will block SSH connection for all IP address.
iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
You can block all SSH communication
through iptables
and allow for particular IP ADDRESS.
In below example,
First two rule is to allow for particular IP Address.
x.x.x.x - Your system IP
Last two rules, will block SSH connection for all IP address.
iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
edited Feb 27 at 6:57
answered Feb 27 at 6:05
bhupender singhbhupender singh
242
242
2
Note that this doesn't block "SSH communication", it just blocks port 22. If I was a user restricted this way, I'd just run an sshd server on port, say, 2222, on the target machine, and then I'd happily connect to it from the source machine with those iptables rules. As mentioned in the comments to this question, first you need to define the scenario.
– dirkt
Feb 27 at 6:44
For that, If your SSH port changes, Use ssh instead of 22. It means if you will change ssh port it will get it from socket example - "2222" . It will block and allow as per iptables rules when your ssh port changes.iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
– bhupender singh
Feb 27 at 6:51
It's not that "the ssh port changes". It's that the user you want to block from using ssh can easily do that by picking some other port you (the admin) have not already blocked. So you can block ports all day long, and keeping adding ports to it, the user you want to block will just switch to a different port. And you can't block all ports...
– dirkt
Feb 27 at 6:54
i edited my answer, i just choose ssh instead of 22. it will automatically take ssh port from socket.
– bhupender singh
Feb 27 at 6:57
1
No, it won't. It will look upssh
in/etc/services
and take the port number from there, which is 22. There is no "ssh port on a socket". And you haven't understood anything of what I was trying to explain.
– dirkt
Feb 27 at 7:10
|
show 2 more comments
2
Note that this doesn't block "SSH communication", it just blocks port 22. If I was a user restricted this way, I'd just run an sshd server on port, say, 2222, on the target machine, and then I'd happily connect to it from the source machine with those iptables rules. As mentioned in the comments to this question, first you need to define the scenario.
– dirkt
Feb 27 at 6:44
For that, If your SSH port changes, Use ssh instead of 22. It means if you will change ssh port it will get it from socket example - "2222" . It will block and allow as per iptables rules when your ssh port changes.iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
– bhupender singh
Feb 27 at 6:51
It's not that "the ssh port changes". It's that the user you want to block from using ssh can easily do that by picking some other port you (the admin) have not already blocked. So you can block ports all day long, and keeping adding ports to it, the user you want to block will just switch to a different port. And you can't block all ports...
– dirkt
Feb 27 at 6:54
i edited my answer, i just choose ssh instead of 22. it will automatically take ssh port from socket.
– bhupender singh
Feb 27 at 6:57
1
No, it won't. It will look upssh
in/etc/services
and take the port number from there, which is 22. There is no "ssh port on a socket". And you haven't understood anything of what I was trying to explain.
– dirkt
Feb 27 at 7:10
2
2
Note that this doesn't block "SSH communication", it just blocks port 22. If I was a user restricted this way, I'd just run an sshd server on port, say, 2222, on the target machine, and then I'd happily connect to it from the source machine with those iptables rules. As mentioned in the comments to this question, first you need to define the scenario.
– dirkt
Feb 27 at 6:44
Note that this doesn't block "SSH communication", it just blocks port 22. If I was a user restricted this way, I'd just run an sshd server on port, say, 2222, on the target machine, and then I'd happily connect to it from the source machine with those iptables rules. As mentioned in the comments to this question, first you need to define the scenario.
– dirkt
Feb 27 at 6:44
For that, If your SSH port changes, Use ssh instead of 22. It means if you will change ssh port it will get it from socket example - "2222" . It will block and allow as per iptables rules when your ssh port changes.
iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
– bhupender singh
Feb 27 at 6:51
For that, If your SSH port changes, Use ssh instead of 22. It means if you will change ssh port it will get it from socket example - "2222" . It will block and allow as per iptables rules when your ssh port changes.
iptables -I INPUT -s x.x.x.x --dport ssh -j ACCEPT
iptables -I OUTPUT -d x.x.x.x --sport ssh -j ACCEPT
IPTABLES -A INPUT --dport ssh -j DROP
IPTABLES -A OUTPUT --sport ssh -j DROP
– bhupender singh
Feb 27 at 6:51
It's not that "the ssh port changes". It's that the user you want to block from using ssh can easily do that by picking some other port you (the admin) have not already blocked. So you can block ports all day long, and keeping adding ports to it, the user you want to block will just switch to a different port. And you can't block all ports...
– dirkt
Feb 27 at 6:54
It's not that "the ssh port changes". It's that the user you want to block from using ssh can easily do that by picking some other port you (the admin) have not already blocked. So you can block ports all day long, and keeping adding ports to it, the user you want to block will just switch to a different port. And you can't block all ports...
– dirkt
Feb 27 at 6:54
i edited my answer, i just choose ssh instead of 22. it will automatically take ssh port from socket.
– bhupender singh
Feb 27 at 6:57
i edited my answer, i just choose ssh instead of 22. it will automatically take ssh port from socket.
– bhupender singh
Feb 27 at 6:57
1
1
No, it won't. It will look up
ssh
in /etc/services
and take the port number from there, which is 22. There is no "ssh port on a socket". And you haven't understood anything of what I was trying to explain.– dirkt
Feb 27 at 7:10
No, it won't. It will look up
ssh
in /etc/services
and take the port number from there, which is 22. There is no "ssh port on a socket". And you haven't understood anything of what I was trying to explain.– dirkt
Feb 27 at 7:10
|
show 2 more comments
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1409687%2fdont-allow-users-to-ssh-to-other-systems%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If the user don't have admin right, maybe restrict the ssh command into the /usr/sbin ? So only those with sudo access can ssh out?
– Darius
Feb 26 at 20:43
1
Similar questions : unix.stackexchange.com/questions/472554/… serverfault.com/questions/660880/…
– Christopher Hostage
Feb 26 at 20:44
3
@Darius presumably the user could provide their own ssh program
– emory
Feb 26 at 20:45
The Server Fault link that @ChristopherHostage provided seems to be exactly what you want/need; if cross-site "duplicates" were permissible flags, I'd be flagging this question as a dupe of it.
– Jeff Zeitlin
Feb 26 at 20:54
3
They could also SSH out to a custom port, like 80, if the 22 is blocked. It really depends on what the scenario is here. Why are you trying to do this, Ken? What systems are they SSHing to that you want to block? Are they internal? Or something custom across the internet?
– HackSlash
Feb 26 at 22:28