업데이트

업데이트

내 로컬 컴퓨터에서 sshX 디스플레이에 대한 인증과 함께 원격 서버로 이동합니다. 이 프로세스에서는 MIT-MAGIC-COOKIES가 사용되고 인증 프로세스가 유효하려면 서버와 클라이언트의 값이 동일해야 한다는 것을 알고 있습니다 .

그러나 원격 서버에 로그인하여 X 디스플레이 항목이 제대로 작동하는지 확인한 경우(예: 응용 프로그램이 내 로컬 컴퓨터에 팝업되는지 xclock확인하기 위해 실행) 쿠키 값을 확인하면 로컬 컴퓨터의 값이 xclock원격 서버에서는 다른 것 같습니다. 명령줄은 다음과 같습니다.

원격 서버의 쿠키 값

chulhyun@chulhyun-Inspiron-3420:~$ ssh -X Black@$labcom
Last login: Wed Jun 25 10:02:25 2014 from 

Black@Black-PC ~
$ xclock    ### xclock appears in local machine.

Black@Black-PC ~
$ xauth list
Black-PC/unix:10  MIT-MAGIC-COOKIE-1  708f623489b1ea129a77e98287d130ca

로컬 컴퓨터의 쿠키 값

chulhyun@chulhyun-Inspiron-3420:~$ xauth list
chulhyun-Inspiron-3420/unix:0  MIT-MAGIC-COOKIE-1  5ddd2ce92004eab53ceee8a64b7b88c0

보시다시피 두 컴퓨터의 쿠키 값은 다릅니다. 그러면 X 디스플레이가 작동하지 않아야 하는 것 아닌가요?

내가 여기서 무엇을 놓치고 있는 걸까요?

$XAUTHORITY추신: 파일 경로가 포함되어 있다고 들었고 xauthority로컬 컴퓨터에서 해당 경로를 확인했습니다.

chulhyun@chulhyun-Inspiron-3420:~$ echo $XAUTHORITY
/var/run/gdm/auth-for-chulhyun-iZfH2u/database

"데이터베이스" 파일을 살펴보니 내용이 이상한 문자로 구성되어 있어서 내용을 읽을 수 없습니다.

^A^@^@^Vchulhyun-Inspiron-3420^@^A0^@^RMIT-MAGIC-COOKIE-1^@^P]?,? ^D??<???      K{??

이것이 질문과 관련이 있습니까?


업데이트

원격 서버 xhost의 결과$XAUTHORITY

Black@Black-PC ~
$ xhost
access control enabled, only authorized clients can connect
SI:localuser:chulhyun

Black@Black-PC ~
$ echo $XAUTHORITY

*정의되지 않은 것으로 밝혀졌습니다 $XAUTHORITY. 이것이 정상인가요?

xhost로컬 머신 의 결과

chulhyun@chulhyun-Inspiron-3420:~$ xhost
access control enabled, only authorized clients can connect
SI:localuser:chulhyun

답변1

SSH가 원격 서버 측에 설정된 터널을 통해 X11 연결의 프록시를 수행하는 방식과 매직 쿠키가 일반적으로 작동하는 방식에 대해 혼란스러워하고 있다고 생각합니다. SSH 매뉴얼 페이지에서:

발췌
The DISPLAY value set by ssh will point to the server machine, but with a 
display number greater than zero.  This is normal, and happens
because ssh creates a “proxy” X server on the server machine for forwarding 
the connections over the encrypted channel.

ssh will also automatically set up Xauthority data on the server machine.  
For this purpose, it will generate a random authorization cookie,
store it in Xauthority on the server, and verify that any forwarded 
connections carry this cookie and replace it by the real cookie when the
connection is opened.  The real authentication cookie is never sent to the 
server machine (and no cookies are sent in the plain).

따라서 원격 서버 측에 표시되는 매직 쿠키는 실제로 로컬 서버(귀하 측)의 실제 매직 쿠키가 아닌 것처럼 보입니다. SSH를 통해 원격 서버에 접속할 때 DISPLAY가 다음과 같이 설정된다는 점을 기억하세요.

$ echo $DISPLAY
localhost:11.0

그리고 마법 쿠키는 다음과 같이 연결됩니다 $DISPLAY.

$ xauth list
remotey.dom.com/unix:11  MIT-MAGIC-COOKIE-1  00f505f4c5731714d30f24a956d4cb8f

그 말은 /unix:11. 이는 일반적으로 로컬 서버의 X11이 아닌 SSH 연결의 로컬 측을 위한 마법 쿠키입니다 :0.

.Xauthority

이 파일에 마법 쿠키가 포함되어 있는 것은 사실이지만 바이너리 파일이고 일반적으로 명령을 통해 상호 작용합니다 xauth. xauth이에 대한 자세한 내용은 의 매뉴얼 페이지를 참조하십시오 .

수동으로 수행

다음을 수행하면 종종 이 메시지가 표시됩니다.

$ ssh -X user1@remotey
$ su - user2
$ xclock

X11 connection rejected because of wrong authentication.
X connection to localhost:10.0 broken (explicit kill or server shutdown).

이는 두 번째 사용자는 .Xauthority처음 로그인할 때 SSH를 통해 전달된 매직 쿠키에 대해 아무것도 모르기 때문입니다. user1인 동안 필수 항목을 생성 xauth add하고 다음과 같이 user2로 사용할 수 있습니다.

$ ssh -X user1@remotey
$ echo $DISPLAY
localhost:10.0

위에서는 # 표시되어 있음을 확인하세요 :10.0. 이제 xauth add해당 디스플레이 #에 필요한 항목을 생성합니다.

$ echo xauth add $(xauth list ${DISPLAY#localhost})
xauth add remotey.dom.com/unix:10 MIT-MAGIC-COOKIE-1 111ef940f6d75b4a9eb64ea3579ef67e

이제 user2가 되어 추가하세요.

$ su - user2
$ xauth add remotey.dom.com/unix:10 MIT-MAGIC-COOKIE-1 111ef940f6d75b4a9eb64ea3579ef67e
$ xclock

그리고 우리는 예상대로 시계 표시를 얻습니다.

메모:위 내용을 이해하고 나면 단일 명령줄에서 작업을 수행할 수도 있습니다.

su를 사용하여
$ xauth extract - ${DISPLAY#localhost} | \
    su - user2 -c "xauth merge -; xclock"
sudo를 사용하세요
$ xauth extract - ${DISPLAY#localhost} | \
    sudo su - user2 -c "xauth merge -; xclock"

참고자료

관련 정보