Skip to content

Commit 7de0905

Browse files
authored
preventing SSH port forwarding (#1296)
preventing SSH port forwarding
2 parents 3b91889 + 3f97a88 commit 7de0905

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

book/04-git-server/sections/setting-up-server.asc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Now you can edit the shell for a user using `chsh <username> -s <shell>`:
107107
$ sudo chsh git -s $(which git-shell)
108108
----
109109

110-
Now, the `git` user can only use the SSH connection to push and pull Git repositories and can't shell onto the machine.
110+
Now, the `git` user can still use the SSH connection to push and pull Git repositories but can't shell onto the machine.
111111
If you try, you'll see a login rejection like this:
112112

113113
[source,console]
@@ -118,6 +118,31 @@ hint: ~/git-shell-commands should exist and have read and execute access.
118118
Connection to gitserver closed.
119119
----
120120

121+
At this point, users are still able to use SSH port forwarding to access any host the git server is able to reach.
122+
If you want to prevent that, you can edit the `authorized_keys` file and prepend the following options to each key you'd like to restrict:
123+
124+
[source,console]
125+
----
126+
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty
127+
----
128+
129+
The result should look like this:
130+
131+
[source,console]
132+
----
133+
$ cat ~/.ssh/authorized_keys
134+
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa
135+
AAAAB3NzaC1yc2EAAAADAQABAAABAQCB007n/ww+ouN4gSLKssMxXnBOvf9LGt4LojG6rs6h
136+
PB09j9R/T17/x4lhJA0F3FR1rP6kYBRsWj2aThGw6HXLm9/5zytK6Ztg3RPKK+4kYjh6541N
137+
YsnEAZuXz0jTTyAUfrtU3Z5E003C4oxOj6H0rfIF1kKI9MAQLMdpGW1GYEIgS9EzSdfd8AcC
138+
IicTDWbqLAcU4UpkaX8KyGlLwsNuuGztobF8m72ALC/nLF6JLtPofwFBlgc+myivO7TCUSBd
139+
LQlgMVOFq1I2uPWQOkOWQAHukEOmfjy2jctxSDBQ220ymjaNsHT4kgtZg2AYYgPqdAv8JggJ
140+
ICUvax2T9va5 gsg-keypair
141+
142+
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa
143+
AAAAB3NzaC1yc2EAAAADAQABAAABAQDEwENNMomTboYI+LJieaAY16qiXiH3wuvENhBG...
144+
----
145+
121146
Now Git network commands will still work just fine but the users won't be able to get a shell.
122147
As the output states, you can also set up a directory in the `git` user's home directory that customizes the `git-shell` command a bit.
123148
For instance, you can restrict the Git commands that the server will accept or you can customize the message that users see if they try to SSH in like that.

0 commit comments

Comments
 (0)