Created
February 25, 2013 15:19
-
-
Save compor/5030515 to your computer and use it in GitHub Desktop.
enable/disable SSH X11 forwarding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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