ssh를 원격 시스템에 사용할 때 ssh_config LC_ALL="en_US.UTF-8"
를 통해 내 보냅니다 sendEnv
. 언제 su - user123
이 변수는 로그인 쉘에 의해 리셋이다. LC_xxx
원격 시스템에서 다른 사용자로 로그인 쉘을 실행할 때이 변수 (및 기타 변수) 를 보존하는 방법이 있습니까?
쉘을 실행하거나 ~/.bashrc
대상 사용자 의 항목을 실행 한 후 수동으로 변수를 내보낼 수 있다는 것을 알고 있지만 ssh
가능한 경우 보낸 원래 값을 유지하려고 합니다. 감사.
편집 : 초기화 된 사용자 환경의 특정 부분이 필요하므로 su -
사용됩니다. 나는 보존하고 싶을뿐LC_xxx
I의 FOUND는 su
환경을 보존하는 옵션이 있습니다 :
-m, -p, --preserve-environment
Preserve the current environment, except for:
...
이렇게하면 로그인 셸과 마찬가지로 대상 사용자의 셸 초기화 파일이 실행되지만 LC_xxx
유효한 값이 이미 포함 된 경우 모든 변수를 테스트하고 초기화 할 수 없습니다.
편집 : 참고로 /etc/profile.d/ssh_lc_vars.sh
내 보낸 LC_xxx 변수와 함께 작동 하는 스크립트를 추가하여이 시스템 전체에 적용 할 수있었습니다 . 또한 .NET으로 처리되지 않는 초기화되지 않은 환경 변수로 추가 작업을 수행해야했습니다 su -ml userxxx
. 아래는 전체 스크립트를 포함 할 수 없기 때문에 더 많은 예입니다. 누군가가 그것을 개선 할 수 있다면 더 좋습니다.
...
# clean up client-side variable for junk
lc_sanitize()
{
arg="$1"
# first, strip underscores
clean="${arg//_/}"
# next, replace spaces with underscores
clean="${clean// /_}"
# now, clean out anything that's not alphanumeric, underscore, hypen or dot
ret="${clean//[^a-zA-Z0-9_\.-]/}"
# return santized value to caller
echo "$ret"
}
# LC_MY_LANG comes from an ssh client environment. If empty,
# this isn't a remote ssh user, but set it locally so this user
# can connect elsewhere where this script runs
if [ -z "$LC_MY_LANG" ]; then
# force an LC_xxx setting for the environment
LC_MY_LANG="en-US.utf-8"
else
# otherwise, use the LC_xxxx variable from the ssh environment
# 2017-01-30 - when using "su --preserve-environment userxxx --login" be sure to fixup needed variables
# shorthand: su -ml user111
export USER=`whoami`
export LOGNAME=${USER}
export HOME=$( getent passwd "$USER" | cut -d: -f6 )
cd ${HOME}
# sanitize variable which was set client-side and log it
u_sanitized=$(lc_sanitize "$LC_MY_LANG")
echo "Notice: LC_MY_LANG sanitized to $u_sanitized from $SSH_CLIENT as user $USER" | logger -p auth.info
fi
# mark variable read-only so user cannot change it then export it
readonly LC_MY_LANG
# set terminal to LC_MY_LANG
export LC_LANG=${LC_MY_LANG}
export LC_MY_LANG
...
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다