[unix] 그래픽 응용 프로그램을 원격으로 실행하기 위해 SSH를 통해 X를 전달하는 방법은 무엇입니까?

Fedora 14 컴퓨터에서 SSH로 연결할 수있는 Ubuntu를 실행하는 컴퓨터가 있습니다. 그래픽 프로그램을 원격으로 실행할 수 있도록 Ubuntu 시스템에서 Fedora로 X를 전달하고 싶습니다. 두 머신 모두 LAN에 있습니다.

-X옵션을 사용하면 SSH에서 X11 전달이 가능 하다는 것을 알고 있지만 일부 단계가 누락 된 것 같습니다.

SSH를 통해 Ubuntu 시스템에서 Fedora로 X를 전달하는 데 필요한 단계는 무엇입니까?



답변

클라이언트 쪽과 서버 쪽 모두에서 X11 전달을 활성화해야합니다.

클라이언트 측-X에 (자본 X) 옵션은 sshX11 포워딩을 가능하게하고, 당신과이 (특정 conection에 모든 연결에 대해 나에 대한) 기본 만들 수 ForwardX11 yes에서 ~/.ssh/config.

서버 측 , X11Forwarding yes에 지정해야한다 /etc/ssh/sshd_config. 기본값은 전달이 아니며 (일부 배포는 기본값으로 설정 /etc/ssh/sshd_config) 사용자는이 설정을 무시할 수 없습니다.

xauth프로그램은 서버 측에 설치되어 있어야합니다. X11 프로그램이 있다면 거기에있을 가능성이 높습니다 xauth. 드문 경우 xauth이지만 비표준 위치 ~/.ssh/rc에 서버를 설치하여 호출 할 수 있습니다 .

서버에서 환경 변수를 설정할 필요는 없습니다. DISPLAY그리고 XAUTHORITY자동으로 적절한 값으로 설정됩니다. ssh를 실행하고 DISPLAY설정되지 않은 경우 ssh가 X11 연결을 전달하지 않음을 의미합니다.

ssh가 X11을 전달하고 있는지 확인 Requesting X11 forwarding하려면 ssh -v -X출력에 포함 된 행을 확인하십시오 . 참고 서버가 응답하지 않습니다 어느 쪽이든, 잠재적 인 공격자 세부 사항을 숨기는 보안상의를.


답변

ssh를 통해 X11 포워딩을 수행하려면 3 가지가 필요합니다.

  1. X11을 전달하도록 클라이언트를 설정해야합니다.
  2. X11 전달을 허용하도록 서버를 설정해야합니다.
  3. 서버는 X11 인증을 설정할 수 있어야합니다.

# 1과 # 2가 있지만 # 3이 없으면 빈 DISPLAY 환경 변수가 생깁니다.

Soup-to-nuts, X11 포워딩을 작동시키는 방법은 다음과 같습니다.

  1. 서버에서 / etc / ssh / sshd_config에 다음이 포함되어 있는지 확인하십시오.

    X11Forwarding yes
    X11DisplayOffset 10
    

    sshd를 SIGHUP해야 할 수도 있으므로 이러한 변경 사항을 적용합니다.

    cat /var/run/sshd.pid | xargs kill -1
    
  2. 서버에 xauth가 설치되어 있는지 확인하십시오.

    belden@skretting:~$ which xauth
    /usr/bin/xauth
    

    xauth가 설치되어 있지 않으면 “빈 디스플레이 환경 변수”문제가 발생합니다.

  3. 클라이언트에서 서버에 연결하십시오. ssh에게 X11 전달을 허용하도록하십시오. 나는 선호한다

    belden@skretting:~$ ssh -X blyman@the-server
    

하지만 너는 좋아할지도 모른다

    belden@skretting:~$ ssh -o ForwardX11=yes blyman@the-server

또는 ~ / .ssh / config에서이를 설정할 수 있습니다.


오늘 관리하지 않는 새 서버에 ssh를 넣을 때이 빈 DISPLAY 환경 변수가 발생했습니다. 누락 된 xauth 부분을 추적하는 것은 약간 재미있었습니다. 여기 내가 한 일과 할 수있는 일이 있습니다.

관리자 인 로컬 워크 스테이션에서 / etc / ssh / sshd_config가 X11을 전달하도록 설정되어 있는지 확인했습니다. localhost로 다시 ssh -X를 넣으면 DISPLAY가 올바르게 설정됩니다.

DISPLAY를 설정 해제하는 것이 그리 어렵지 않았습니다. 나는 sshd와 ssh가 올바르게 설정하기 위해 무엇을하고 있는지보아야했습니다. 여기 내가 한 모든 일의 전체 결과가 있습니다.

    blyman@skretting:~$ mkdir ~/dummy-sshd
    blyman@skretting:~$ cp -r /etc/ssh/* ~/dummy-sshd/
    cp: cannot open `/etc/ssh/ssh_host_dsa_key' for reading: Permission denied
    cp: cannot open `/etc/ssh/ssh_host_rsa_key' for reading: Permission denied

sudo를 사용하여 ssh_host_ {dsa, rsa} _key 파일을 강제로 복사하는 대신 ssh-keygen을 사용하여 더미 파일을 직접 만들었습니다.

    blyman@skretting:~$ ssh-keygen -t rsa -f ~/dummy-sshd/ssh_host_rsa_key
    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/blyman/dummy-sshd/ssh_host_rsa_key.
    Your public key has been saved in /home/blyman/dummy-sshd/ssh_host_rsa_key.pub.

-t dsa로 헹굼 및 반복 :

    blyman@skretting:~$ ssh-keygen -t dsa -f ~/dummy-sshd/ssh_host_dsa_key
    # I bet you can visually copy-paste the above output down here

올바른 새 ssh_host 키 파일을 가리 키도록 ~ / dummy-sshd / sshd_config를 편집하십시오.

    # before
    blyman@skretting:~$ grep ssh_host /home/blyman/dummy-sshd/sshd_config
    HostKey /etc/ssh/ssh_host_rsa_key
    HostKey /etc/ssh/ssh_host_dsa_key

    # after
    blyman@skretting:~$ grep ssh_host /home/blyman/dummy-sshd/sshd_config
    HostKey /home/blyman/dummy-sshd/ssh_host_rsa_key
    HostKey /home/blyman/dummy-sshd/ssh_host_dsa_key

비 분리 모드의 새 포트에서 sshd를 실행하십시오.

    blyman@skretting:~$ sshd -p 50505 -f ~/dummy-sshd/sshd_config -d
    sshd re-exec requires execution with an absolute path

그 경로를 더 잘 수정하십시오.

    blyman@skretting:~$ /usr/sbin/sshd -p 50505 -f ~/dummy-sshd/sshd_config -d
    debug1: sshd version OpenSSH_5.5p1 Debian-4ubuntu6
    debug1: read PEM private key done: type RSA
    debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
    debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
    debug1: private host key: #0 type 1 RSA
    debug1: read PEM private key done: type DSA
    debug1: Checking blacklist file /usr/share/ssh/blacklist.DSA-1024
    debug1: Checking blacklist file /etc/ssh/blacklist.DSA-1024
    debug1: private host key: #1 type 2 DSA
    debug1: setgroups() failed: Operation not permitted
    debug1: rexec_argv[0]='/usr/sbin/sshd'
    debug1: rexec_argv[1]='-p'
    debug1: rexec_argv[2]='50505'
    debug1: rexec_argv[3]='-f'
    debug1: rexec_argv[4]='/home/blyman/dummy-sshd/sshd_config'
    debug1: rexec_argv[5]='-d'
    Set /proc/self/oom_adj from 0 to -17
    debug1: Bind to port 50505 on 0.0.0.0.
    Server listening on 0.0.0.0 port 50505.
    debug1: Bind to port 50505 on ::.
    Server listening on :: port 50505.

새 터미널을 열고 포트 50505의 localhost에 ssh를 입력하십시오.

    blyman@skretting:~$ ssh -p 50505 localhost
    The authenticity of host '[localhost]:50505 ([::1]:50505)' can't be established.
    RSA key fingerprint is 81:36:a5:ff:a3:5a:45:a6:90:d3:cc:54:6b:52:d0:61.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '[localhost]:50505' (RSA) to the list of known hosts.
    Linux skretting 2.6.35-32-generic #67-Ubuntu SMP Mon Mar 5 19:39:49 UTC 2012 x86_64 GNU/Linux
    Ubuntu 10.10

    Welcome to Ubuntu!
     * Documentation:  https://help.ubuntu.com/

    1 package can be updated.
    0 updates are security updates.

    Last login: Thu Aug 16 15:41:58 2012 from 10.0.65.153
    Environment:
      LANG=en_US.UTF-8
      USER=blyman
      LOGNAME=blyman
      HOME=/home/blyman
      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
      MAIL=/var/mail/blyman
      SHELL=/bin/bash
      SSH_CLIENT=::1 43599 50505
      SSH_CONNECTION=::1 43599 ::1 50505
      SSH_TTY=/dev/pts/16
      TERM=xterm
      DISPLAY=localhost:10.0
    Running /usr/bin/xauth remove unix:10.0
    /usr/bin/xauth add unix:10.0 MIT-MAGIC-COOKIE-1 79aa9275ced418dd445d9798b115d393

마지막 세 줄을보십시오. 유감스럽게도 DISPLAY가 설정되었고 / usr / bin / xauth의 멋진 두 줄이있었습니다.

거기에서 내 / usr / bin / xauth를 /usr/bin/xauth.old로 옮기고 ssh에서 연결을 끊고 sshd를 중지 한 다음 sshd 및 ssh를 localhost로 다시 시작하는 것은 어린이 놀이였습니다.

/ usr / bin / xauth가 사라 졌을 때 내 환경에 DISPLAY가 반영되지 않았습니다.


여기에는 화려한 일이 없습니다. 주로 로컬 컴퓨터에서이를 재현하기 위해 제정신의 접근 방식을 선택하는 데 운이 좋았습니다.


답변

다음을 확인하십시오.

  • 당신은 한 xauth서버에 설치 (: 참조 xauth info/ xauth list).
  • 서버에서 /etc/ssh/sshd_config파일에는 다음 줄이 있습니다.

    X11Forwarding yes
    X11DisplayOffset 10
    X11UseLocalhost no
    
  • 클라이언트 쪽에서 ~/.ssh/config파일에는 다음 줄이 있습니다.

    Host *
      ForwardAgent yes
      ForwardX11 yes
    
  • 클라이언트쪽에 X 서버가 설치되어 있습니다 (예 : macOS : XQuartz; Windows : Xming).


그런 다음 SSH를 사용하여 X11 전달을 수행 하려면 명령 에 추가 -X해야합니다ssh . 예 :

ssh -v -X user@host

다음은 확인 DISPLAY입니다 하지 으로 비어 :

echo $DISPLAY

그렇다면 ssh ( -v)에 대한 자세한 매개 변수 가 있으면 경고가 있는지 확인하십시오 ( 예 :

debug1: No xauth program.
Warning: untrusted X11 forwarding setup failed: xauth key data not generated

위와 같이 신뢰할 수없는 X11 이있는 경우 대신 플래그시도-Y 하십시오 (호스트를 신뢰하는 경우).

ssh -v -Y user@host

참조 : “신뢰할 수없는 X11 포워딩 설정 실패 : 경고 xauth를 키 데이터가 생성되지”무엇 -X와 ssh’ing 때 의미?


경고 가없는 경우 : xauth data 없음.Xauthority , 예를 들어 새 파일 을 생성하려고 할 수 있습니다.

xauth generate :0 . trusted
xauth list

참조 : 새 .Xauthority 파일 작성 / 재 구축


위와 다른 경고가 표시되면 추가 힌트를 따르십시오.



답변

수정 사항은이 줄을 다음에 추가하는 것입니다 /etc/ssh/sshd_config.

X11UseLocalhost no

https://joshua.hoblitt.com/rtfm/2013/04/how_to_fix_x11_forwarding_request_failed_on_channel_0/


답변

Windows 10에서 Ubuntu bash를 실행 ssh -X 하여 원격 서버에서 GUI 환경 가져 오기

  • 먼저

다음을 모두 설치하십시오. Window에서 설치하십시오 Xming. Ubuntu bash에서을 사용 sudo apt install하여 설치하십시오 ssh xauth xorg.

sudo apt install ssh xauth xorg
  • 둘째

ssh_config파일이 들어있는 폴더로 이동하십시오 /etc/ssh.

  • 제삼

ssh_config관리자로 편집하십시오 (USE sudo). 내부 ssh_config해시를 제거 #선에 ForwardAgent, ForwardX11, ForwardX11Trusted,과에 해당 인수를 설정 yes.

# /etc/ssh/ssh_config

Host *
    ForwardAgent yes
    ForwardX11 yes
    ForwardX11Trusted yes
  • 앞으로

에서 ssh_config파일, 전면 해시를 제거 #하기 전에 Port 22하고 Protocol 2, 또한 xauth를 파일 위치를 상태로 파일의 끝에 새 줄을 추가, XauthLocaion /usr/bin/xauth, xauth를 파일의 당신의 자신의 경로를 쓰기 기억한다.

# /etc/ssh/ssh_config

#   IdentifyFile ...
    Port 22
    Protocol 2
#   Cipher 3des
#   ...
#   ...
    ...
    ...
    GSSAPIDelegateCredentials no
    XauthLocaion /usr/bin/xauth
  • 다섯째

이제 ssh_config파일 편집이 완료되었으므로 편집기를 떠날 때 저장하십시오. 이제 폴더 ~또는 로 이동 하여 파일에 $HOME추가 하고 저장하십시오.export DISPLAY=localhost:0.bashrc

# ~/.bashrc
...
...
export DISPLAY=localhost:0
  • 마지막

우리는 거의 끝났습니다. bash 쉘을 다시 시작 Xming하고 프로그램을 열고 를 사용하십시오 ssh -X yourusername@yourhost. 그런 다음 GUI 환경을 즐기십시오.

ssh -X yourusername@yourhost

문제는 Windows의 Ubuntu 하위 시스템에도 있으며 링크는

https://gist.github.com/DestinyOne/f236f71b9cdecd349507dfe90ebae776


답변

추가 X11UseLocalhost no/etc/ssh/sshd_config하고 SSH 서버를 다시 시작합니다.

표시되지 않으면 xauth가 올바르게 설치되었는지 확인한 후 다시 시도하십시오.

RHE / CEntos에는이 문제가 없습니다. 이것은 우분투입니다!


답변

나에게 문제는 / tmp 파일 시스템의 nodev 마운트 옵션에있었습니다. X11에는 특별한 파일이 생성되어야합니다.

따라서 별도의 파티션이나 디스크를 사용하는 경우 / tmp 파일 시스템에 대한 마운트 옵션이 무엇인지 확인하십시오.