Skip to content

Instantly share code, notes, and snippets.

@compor
Created February 25, 2013 15:19
Show Gist options
  • Select an option

  • Save compor/5030515 to your computer and use it in GitHub Desktop.

Select an option

Save compor/5030515 to your computer and use it in GitHub Desktop.
enable/disable SSH X11 forwarding
#!/bin/bash
SSHD_CONFIG=/etc/ssh/sshd_config
SSH_SVC=/etc/init.d/sshd
v=`grep -m 1 -e "X11Forwarding" ${SSHD_CONFIG} | awk '{ if( $0 ~ /^#/ ) print "no"; else print $2; }'`
enabled=0;
if [ ${v} == 'yes' ]; then
enabled=1;
fi
case "$1" in
enable)
if [ ${enabled} -eq 0 ]; then
sed -i 's/[#]*X11Forwarding[ ]*[a-z]*/X11Forwarding yes/' ${SSHD_CONFIG}
${SSH_SVC} restart
else
echo "already enabled"
fi
;;
disable)
if [ ${enabled} -ne 0 ]; then
sed -i 's/[#]*X11Forwarding[ ]*[a-z]*/X11Forwarding no/' ${SSHD_CONFIG}
${SSH_SVC} restart
else
echo "already disabled"
fi
;;
*)
echo "unrecognized option"
exit 2
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment