OpenSSH
주의 참고 문서! | |
내용의 일부 또는 전체가 검증되지 않아 잠재적 유무형의 손실을 유발할 수 있는 문서입니다. |
서문[편집]
텔넷과 FTP는 쓰지 말고 ssh와 sftp를 써라.
소개[편집]
모르면 간첩이라고 하는 sshd다. 보안이 간지나는(?) OpenBSD 프로젝트에서 관리하는 프로젝트 중 일반인이 가장 많이 쓰는 프로젝트이다.
설치[편집]
대부분은 이미 되어 있는 상태이므로 생략.
참고[편집]
만약 iptables를 쓰고 있다면,
{{#ifeq: msg|user|~|{{#ifeq: misc|user|~ iptables -t filter -L INPUT|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~ {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} iptables -t filter -L INPUT}}}}
filter 테이블의 INPUT 체인의 기본 정책이 ACCEPT인지를 확인하거나,
{{#ifeq: msg|user|~|{{#ifeq: misc|user|~ iptables -S |{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~ {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} iptables -S }}}}
-j 다음에 ACCEPT 인지 DROP 인지 확인하도록 한다.
만약 8022 번을 쓰려고 하는데 DROP 상태라면,
{{#ifeq: msg|user|~|{{#ifeq: misc|user|~ iptables -D INPUT -p tcp --dport 8022 -j DROP;|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~ {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} iptables -D INPUT -p tcp --dport 8022 -j DROP;}}}}
{{#ifeq: msg|user|~|{{#ifeq: misc|user|~ iptables -A INPUT -p tcp --dport 8022 -j ACCEPT;|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~ {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} iptables -A INPUT -p tcp --dport 8022 -j ACCEPT;}}}}
그리고 iptables 를 다시 시작한다. (systemd 기반으로 바뀌었으므로 수정)
{{#ifeq: msg|user|~|{{#ifeq: misc|user|~ sudo systemctl restart iptables.service|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~ {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} sudo systemctl restart iptables.service}}}}
설정[편집]
다음 명령 또는,
{{#ifeq: msg|user|~|{{#ifeq: misc|user|~ su|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~ {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} su}}}}
{{#ifeq: msg|msg|Password:|{{#ifeq: misc|msg|Password: {{{2}}}|{{#ifeq: root|msg|ubuntu-korea|{{#ifeq: user|msg|user@ubuntu-korea|(undefined)}}}} Password: {{#ifeq: root|msg|#|{{#ifeq: user|msg|$|$}}}} {{{2}}}}}}}
{{#ifeq: msg|root|user|{{#ifeq: misc|root|user vi /etc/ssh/sshd_config|{{#ifeq: root|root|ubuntu-korea|{{#ifeq: user|root|user@ubuntu-korea|(undefined)}}}} user {{#ifeq: root|root|#|{{#ifeq: user|root|$|$}}}} vi /etc/ssh/sshd_config}}}}
다음 명령을 실행(권장)하고,
{{#ifeq: msg|user|~|{{#ifeq: misc|user|~ sudo vi /etc/ssh/sshd_config|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~ {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} sudo vi /etc/ssh/sshd_config}}}}
포트 번호를 (원하는 대로) 수정하고, <syntaxhighlight lang="bash">
- Package generated configuration file
- See the sshd(8) manpage for details
- What ports, IPs and protocols we listen for
- 아래 숫자를 원하는 포트번호로 수정
Port 3065
- Use these options to restrict which interfaces/protocols sshd will bind to
- ListenAddress ::
- ListenAddress 0.0.0.0
</syntaxhighlight>
sftp 활성 상태를 봐준 후, <syntaxhighlight lang="bash">
- override default of no subsystems
Subsystem sftp /usr/lib64/misc/sftp-server </syntaxhighlight>
필요에 따라 X11 포워딩 옵션을 활성화한다(보안 주의!::하지만 VNC보단 이게 훨 낫다). <syntaxhighlight lang="bash"> X11Forwarding yes </syntaxhighlight>
원하면 터널링도 (...) <syntaxhighlight lang="bash"> PermitTunnel yes </syntaxhighlight>
클라이언트[편집]
리눅스[편집]
간지나게 콘솔에서 실행하면 된다.
{{#ifeq: msg|user|~|{{#ifeq: misc|user|~ ssh ID@host -p [port]|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~ {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} ssh ID@host -p [port]}}}}
X11 포워딩을 사용하려면 -X 옵션(경고 뜨면 -Y)을 쓰면 된다. 만약 이 옵션을 쓰면 로컬 윈도우 환경에 원격 GUI 프로그램을 실행할 수 있다. 물론 GUI 프로그램을 띄우려면 ssh 접속 명령을 "당연히" Konsole이나 gnome-terminal 같은 GUI 기반 터미널 프로그램에서 실행해야 한다.
파일 복사는 요래요래 하면 된다.
{{#ifeq: msg|user|incoming|{{#ifeq: misc|user|incoming scp -P 3182 ~/yadong.zip foo@baz.biz:/home/foo/.|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} incoming {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} scp -P 3182 ~/yadong.zip foo@baz.biz:/home/foo/.}}}}
반대로라면,
{{#ifeq: msg|user|incoming|{{#ifeq: misc|user|incoming scp -P 3182 foo@baz.biz:/home/foo/yadong.zip ~/.|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} incoming {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} scp -P 3182 foo@baz.biz:/home/foo/yadong.zip ~/.}}}}
뭐 이런식이다.설마 경찰에 잡혀가진 않겠지?
맥[편집]
역시 마찬가지로 ssh 클라이언트를 따로 구하는 삽질은 안해도 된다. 대신 X11 포워딩을 사용하려면 MacOSX 환경이 X11 디스플레이 서버와 약간 다르므로 XQuartz를 받아서 설치한 다음에 X11 창을 띄우고 -Y 옵션을 써서 접속해야 한다.
윈도우[편집]
제일 까탈스러운게 윈도우다. Windows 10은 어떨라나 몰라 iPutty 또는 ssh에 들어갈 수 있는 별도의 클라이언트가 필요하다. 아니면 넷사랑컴퓨터에서 필요한 프로그램(XShell, XFtp)을 받아다 써도 된다. 원격으로 GUI 기반의 뭔가를 실행하려면 Xming 이 필요하다. 방법을 다 적으려고 하는데 아뿔싸. 원래 윈도우를 안쓰기 때문에 따로 머신을 켜기가 귀찮아 설명을 쓰기가 귀찮다. 이 곳을 참조하면 되겠다.
공개 키 인증[편집]
경고 | |
안해봤으므로 검증이 필요함(...) |
nixCraft의 게시물에서 발췌했다<ref>http://www.cyberciti.biz/faq/how-to-set-up-ssh-keys-on-linux-unix/</ref>.
설정[편집]
/etc/ssh/sshd_config 파일을 열어서 다음 부분을 찾아서 값을 no로 고친다. <syntaxhighlight lang="bash"> PasswordAuthentication yes </syntaxhighlight>
주: 이거만 해봤는데 암호 로그인 잘됨 ㅡ.ㅡ; 물론 다음도 같이 no로 고쳐야 한다.
<syntaxhighlight lang="bash"> UsePAM yes </syntaxhighlight>
설정이 끝나면 당연히 sshd를 다시 시작해야 한다.
키 생성[편집]
다음 명령을 내려 기본 길이 2048 bit의 RSA키를 생성한다.
{{#ifeq: msg|user|~/.ssh|{{#ifeq: misc|user|~/.ssh ssh-keygen -t rsa|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~/.ssh {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} ssh-keygen -t rsa}}}}
암호를 입력하여 설정하면 키를 들고 서버에 들어올 때 암호를 따로 입력해야 한다. 싫으면 그냥 엔터키를 누르면 된다.
다 만들고 나면 $HOME/.ssh/ 에 id_rsa와 id_rsa.pub 파일 두 개가 나타난다. 이 중 id_rsa는 ...
{{#ifeq: msg|user|~/.ssh|{{#ifeq: misc|user|~/.ssh chmod 600 ~/.ssh/id_rsa;|{{#ifeq: root|user|ubuntu-korea|{{#ifeq: user|user|user@ubuntu-korea|(undefined)}}}} ~/.ssh {{#ifeq: root|user|#|{{#ifeq: user|user|$|$}}}} chmod 600 ~/.ssh/id_rsa;}}}}
보안상 반드시 해주자.
그리고, id_rsa.pub는 원하는 클라이언트로 가져오면 된다.
참고[편집]
<references/>