最近需要su到其它帐号上去做事情。但是su出来的shell总是受到输入su的shell的各种环境变量的污染,比如说会残留原来的XAUTHORITY、XDG_SESSION_ID等环境变量,导致有图形界面的程序出现各种问题。
找到的唯一正常的姿势是从tty登录,开一个byobu,然后切回桌面,从终端里面su进去,链接到那个byobu,设定DISPLAY,启动应用程序。我觉得这样太麻烦了,要打好多字。
有没有更加正确的姿势?
(命令“su - user”,也会残留下之前说的那些变量)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJYCe7iAAoJEIADh2DFg7VOUuwQAJGWhZFO/y7j4KOa5qT5QG6y
CZq33neSq2iTk8d4fGyKIbNWR+6BJBrAKARUVdpk5Zf1/cU8YeoMwj3svswldxR0
iz1/jkSTvNiZ8Tr1FA3go/k939kvbx49XMj1s/tqjqFOWG+HiBgT7aYEO3EQsFbN
+TZt7MMaJipSAVdO/nPD5ZELIPYIO3z7DR/QT8kuPe6+/UDF66cylcfp/OpZtv/o
JkMz0xgQqrrjAFIwoyQEQuKxGMB9Z+R6i/7/9YIBLOnxNw8KEul2NNlAuKsMhqtP
+8UYXDV2R6DpASBFgMxYRyliozzUZCKgJlX2dIXS+3S0XlFfkr73ysqw27NfCiIb
hJPQaNhnuQplNGUs1UexIa+Y0JUGj//0zXGNsbhrRzKbKxTHIIkqapvFPHgUb0sv
24TUs+zN++5E1WXZ/VrvRb6cx4qvRZlWSryyhfepESNzJry2dyVO/y3C5YnVXXJ0
8dGyPev/+1ZlsnqB+XoiXqnZDqq8NtStsLmbta067zPGhTTCU88oXqCpRTJHLb3s
Dza9/BLq5cuQ9AKAB37Lh+T/m21VL/U8OkwCg0CWWYgD6AiegRuJAarEPzV9jePj
JAkg3YedNnruYd5/DWi57AAkFIjJ9RDjRA4TRGHwJ7zQfHd0PMAnRX8tKz6XrS5v
rSBDZNT/P5IAMX25XnSl
=2AfX
-----END PGP SIGNATURE-----
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/d/optout。
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/d/optout。
----Cheng,Best Regards
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛上的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/d/optout。
----Cheng,Best Regards
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛上的“Shanghai Linux User Group”群组。
--要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛上的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
不顶用,试验了“env -i su - user”,仍然看到了污染进来的XDG_xxx变量
简单测试了一下,只要加了 - 环境变量就没有带过去了,甚至并不需要用到env -i。
很可能他的那些所谓带过去的变量是从rc里读来的。
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛上的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
----------8<-----------------------------
[xuxd@lion ~]$ export test=just-a-test
[xuxd@lion ~]$ echo $test
just-a-test
[xuxd@lion ~]$ su
Password:
[root@lion xuxd]# echo $test
just-a-test
[root@lion xuxd]# exit
exit
[xuxd@lion ~]$ su -
Password:
[root@lion ~]# echo $test
[root@lion ~]# exit
logout
[xuxd@lion ~]$ sh
sh-4.3$ echo $test
just-a-test
sh-4.3$ exit
exit
[xuxd@lion ~]$ env -i sh
sh-4.3$ echo $test
sh-4.3$ exit
exit
[xuxd@lion ~]$
----------8<-----------------------------
另外,man su 是这么说的:
-, -l, --login
Start the shell as a login shell with an environment
similar to a real login:
o clears all the environment variables
except TERM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
被su的用户是新建的,从tty登录和ssh登录都没有问题。env -i env没有输出。
考虑到污染进来的变量只有XDG_xxx,怀疑是桌面环境的奇特作用。系统是Debian
8,DE是Cinnamon。
在 2016年10月22日 02:03, Zhang Cheng 写道:
> > On Fri, Oct 21, 2016 at 10:31 PM, 宋 为 <leo_s...@outlook.com
<mailto:leo_songwei@outlook.com>> wrote: > > 不顶用,试验了“env -i su -
user”,仍然看到了污染进来的XDG_xxx变量 > > > 1、先 env -i env,确认 env
是否真的把所有的环境变量都 unset 了。 > 2、请确认 $user 的 $SHELL
启动时读取了哪些rc文件(如profile、bashrc等),XDG_xxx 是否来自这些rc文件。
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJYCqA/AAoJEIADh2DFg7VOxjoP/jUcE0IQbCvK5V4XZryqZCYH
jkbH8G0WNmCAPOZj9S3Hrl+ky9PACsUxhTKQMTX96CHsxYZ/aRkpqGTdtpzuD8Pa
dZIP7zIbXEeBXnegeXf2i73rgJmDfyMZkbAuf5163vfF1PNx4q/WTyJ8ao0vwcY1
D36mBR9Fi8ZEYnPh/Vk1s9Ha87RdVRcmHrHaYeRD1zH0TGH4sn2CMSlBCUlkexJA
xB3i0Z1kTU5uFp5U6YORC+VLIPWSWkK6vxjOPar2bJ9QQogwp1EFlDecNqdd1m2w
fWpQ3qseFIGk8plXigJ4sv7KPfRTJ0xB3dHalRIc8Ai0L7iiXUYgGhskuTROb2dh
pEMRKOWkSwe5OHgI0M88tXgYMNSxylPumQ8sLYRPaYPzA9R8bRL0g+FYHLb2Efnb
qXaOK4h01ME6mrRvKDbOjUc3kHM3QEOlUrGK76fwUh0qKJwyHbdv0Az5CiWfZSEi
CaqnL02rIO3nM3s5/So5R0mD2dzR1N1xnMj9jNUI464Sp6A7vbluwU/oZx8/pX5C
o3piTUxpcr/tdsHT3IE97phqF212boCGCJsilbpphiTOESz2y6ALcuMDH3DchwLs
8D2+/IERcAKJ92thU5q1kpibqBkwQn7ATte8EiCPJY23Q6gukotMfJ+TQ6h01S8b
vfC3SqJw8VeIqs4cEICQ
=B465
-----END PGP SIGNATURE-----
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/d/optout。
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。