사용자가 SSH 터널을 설정하도록 허용하지만 다른 것은 설정하지 않습니다.
사용자가 특정 포트 (예 : 5000)의 특정 컴퓨터에 SSH 터널을 설정하도록 허용하고 싶지만이 사용자를 가능한 한 많이 제한하고 싶습니다. (인증은 공개 / 개인 키 쌍으로 이루어집니다).
관련 ~ / .ssh / authorized_keys 파일을 편집해야한다는 것을 알고 있지만 여기에 어떤 콘텐츠를 넣을지 정확히 모르겠습니다 (공개 키 제외).
우분투 11.10에서 -T를 사용하거나 사용하지 않고 전송되는 ssh 명령을 차단하고 scp 복사를 차단하면서 포트 포워딩을 허용 할 수 있음을 발견했습니다.
특히 나는 localhost : 6379에 바인딩 된 "somehost"에 redis-server가 있는데, ssh 터널을 통해 키 파일이 있고 ssh를 사용하는 다른 호스트와 안전하게 공유하고 싶습니다.
$ ssh -i keyfile.rsa -T -N -L 16379:localhost:6379 someuser@somehost
이로 인해 "somehost"의 redis-server "localhost"포트 6379가 ssh 명령을 실행하는 호스트에 로컬로 나타나고 "localhost"포트 16379로 다시 매핑됩니다.
원격 "somehost"에서 내가 authorized_keys에 사용한 것입니다.
cat .ssh/authorized_keys (portions redacted)
no-pty,no-X11-forwarding,permitopen="localhost:6379",command="/bin/echo do-not-send-commands" ssh-rsa rsa-public-key-code-goes-here keyuser@keyhost
no-pty는 터미널을 열려는 대부분의 ssh 시도를 수행합니다.
permitopen은 전달이 허용되는 포트를 설명합니다.이 경우 포트 6379는 전달하려는 redis-server 포트입니다.
command = "/ bin / echo do-not-send-commands"는 누군가 또는 무언가가 ssh -T 또는 기타를 통해 호스트에 명령을 보낼 수있는 경우 "do-not-send-commands"를 반환합니다.
최근 Ubuntu man sshd
에서 authorized_keys / 명령은 다음과 같이 설명됩니다.
command = "command"이 키가 인증에 사용될 때마다 명령이 실행되도록 지정합니다. 사용자가 제공 한 명령 (있는 경우)은 무시됩니다.
scp 보안 파일 복사를 사용하려는 시도는 "do-not-send-commands"라는 에코와 함께 실패합니다. sftp도이 구성에서 실패합니다.
이전 답변에서 만든 제한된 쉘 제안도 좋은 생각이라고 생각합니다. 또한 여기에 설명 된 모든 내용은 "man sshd"를 읽고 "authorized_keys"를 검색하여 확인할 수 있다는 데 동의합니다.
사용자의 셸을 제한된 셸로 설정하고 싶을 것입니다 . 사용자의 ~ / .bashrc 또는 ~ / .bash_profile에서 PATH 변수를 설정 해제하면 명령을 실행할 수 없습니다. 나중에, 당신은 당신처럼, 제한된 명령을 실행하기 위해 사용자를 허용 할 결정하는 경우 less
또는 tail
예를 들어, 당신은 (예 : 별도의 디렉토리에 허용 된 명령을 복사 할 수 있습니다 /home/restricted-commands
)와에 지점의 경로를 업데이트 그 디렉토리.
no-X11-forwarding과 같은 authorized_keys 옵션 외에 실제로 요청하는 옵션이 정확히 하나 있습니다 : permitopen = "host : port". 이 옵션을 사용하면 사용자는 지정된 호스트 및 포트에 대한 터널 만 설정할 수 있습니다.
AUTHORIZED_KEYS 파일 형식에 대한 자세한 내용은 man sshd를 참조하십시오.
내 해결책은 대화 형 쉘없이 터널링 만 할 수있는 사용자에게 / etc / passwd의 해당 쉘 을 / usr / bin / tunnel_shell로 설정하는 것 입니다.
무한 루프 가있는 / usr / bin / tunnel_shell 실행 파일을 만드십시오 .
#!/bin/bash
trap '' 2 20 24
clear
echo -e "\r\n\033[32mSSH tunnel started, shell disabled by the system administrator\r\n"
while [ true ] ; do
sleep 1000
done
exit 0
여기에 자세히 설명되어 있습니다. http://blog.flowl.info/2011/ssh-tunnel-group-only-and-no-shell-please/
로그인을위한 공개 키를 사용하여 authorized_keys 파일을 설정할 수 있습니다. 확실하지 않은 것은 해당 계정이 수행 할 수있는 작업을 제한하는 데 필요한 추가 정보입니다. 예를 들어 다음과 같은 명령을 입력 할 수 있습니다.
no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding
당신은 당신의 authorized_keys 파일에 다음과 같은 줄을 원할 것입니다.
permitopen="host.domain.tld:443",no-pty,no-agent-forwarding,no-X11-forwardi
ng,command="/bin/noshell.sh" ssh-rsa AAAAB3NzaC.......wCUw== zoredache
If you want to do allow access only for a specific command -- like svn -- you can also specify that command in the authorized keys file:
command="svnserve -t",no-port-forwarding,no-pty,no-agent-forwarding,no-X11-forwarding [KEY TYPE] [KEY] [KEY COMMENT]
From http://svn.apache.org/repos/asf/subversion/trunk/notes/ssh-tricks
Here you have a nice post that I found useful: http://www.ab-weblog.com/en/creating-a-restricted-ssh-user-for-ssh-tunneling-only/
The idea is: (with the new restricted username as "sshtunnel")
useradd sshtunnel -m -d /home/sshtunnel -s /bin/rbash
passwd sshtunnel
Note that we use rbash (restricted-bash) to restrict what the user can do: the user cannot cd (change directory) and cannot set any environment variables.
Then we edit the user's PATH env variable in /home/sshtunnel/.profile
to nothing - a trick that will make bash not find any commands to execute:
PATH=""
Finally we disallow the user to edit any files by setting the following permissions:
chmod 555 /home/sshtunnel/
cd /home/sshtunnel/
chmod 444 .bash_logout .bashrc .profile
I made a C program which looks like this:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
void sig_handler(int signo)
{
if (signo == SIGHUP)
exit(0);
}
int main()
{
signal(SIGINT, &sig_handler);
signal(SIGTSTP, &sig_handler);
printf("OK\n");
while(1)
sleep(1);
exit(0);
}
I set the restricted user's shell to this program.
I don't think the restricted user can execute anything, even if they do ssh server command
, because the commands are executed using the shell, and this shell does not execute anything.
See this post on authenticating public keys.
The two main things you need to remember are:
- Make sure you
chmod 700 ~/.ssh
- Append the public key block to authorized-keys
You will generate a key on the users machine via whatever ssh client they are using. pUTTY for example has a utility to do this exact thing. It will generate both a private and public key.
The contents of the public key file generated will be placed in the authorized_keys file.
Next you need to make sure that the ssh client is configured to use the private key that generated the public key. It's fairly straight forward, but slightly different depending on the client being used.
참고URL : https://stackoverflow.com/questions/8021/allow-user-to-set-up-an-ssh-tunnel-but-nothing-else
'IT story' 카테고리의 다른 글
배수 (0) | 2020.09.03 |
---|---|
점이없는 파일 (확장자가없는 모든 파일)을 gitignore 파일에 어떻게 추가합니까? (0) | 2020.09.03 |
여러 이미지의 유사성을 비교하기위한 이미지 지문 (0) | 2020.09.03 |
클래스 경로에서 Java 패키지의 모든 클래스를 어떻게 읽습니까? (0) | 2020.09.03 |
git은 xcodeproject / project.pbxproj 파일을 무시해야합니까? (0) | 2020.09.03 |