Acesso remoto utilizando FreeNX
As maiores reclamações de usuários remotos que utilizam o Linux e que precisam usar a parte gráfica é a demora para abrir aplicativos e configuração não intuitiva. O FreeNX é uma ferramenta que permite acessos através de um cliente gráfico, utilizando S.O. Windows ou Linux com uma velocidade surpreendente. Indicado para quem precisa dar manutenção a servidores ou que trabalha como homeOffice.
Parte 2: Configuração do FreeNX
A configuração do Freenx é bem simples, foram feitas algumas alterações em seu arquivo de configuração, que fica em /etc/nxserver/node.conf.
Algumas alterações importantes:
Algumas alterações importantes:
- Porta de conexão que foi mudada da 22 para a 37775;
- Modo de autenticação pelo arquivo passwd do sistema;
- Efetuar "log" do FreeNX em modo critico;
- Utilizar o Fluxbox como padrão de interface gráfica.
##########################################################
# General FreeNX directives
##########################################################
# The host name which is used by NX server. It's should be used if it's
# different than the default hostname (as returned by `hostname`)
SERVER_NAME="$(hostname)"
# The port number where local 'sshd' is listening.
SSHD_PORT=37775
##########################################################
# Authentication / Security directives
##########################################################
# This adds the passdb to the possible authentication methods
ENABLE_PASSDB_AUTHENTICATION="0"
# This adds SSH to the possible authentication methods. For it to work sshd
# must be set up at localhost accepting password authentication.
ENABLE_SSH_AUTHENTICATION="1"
# Require all users to be in the passdb, regardless of authentication method
ENABLE_USER_DB="0"
##########################################################
# Logging directives
##########################################################
# This directives controls the verbosity of the server-wide log.
# 0: No Logging
# 1: Errors
# 2: Warnings
# 3: Important information
# 4: Server - Client communication
# 5: Information
# 6: Debugging information
# 7: stderror of some applications
NX_LOG_LEVEL=7
# Before turning logging on, please make sure that NX_LOGFILE is
# writeable for the "nx" user
NX_LOGFILE=/var/log/nxserver.log
##########################################################
# Path directives
##########################################################
# The command binary for the default window manager. If set it is run when a
# 'unix-custom' session is requested by the NX Client and an application
# to run is specified. It defaults to empty (ie no WM is run).
# If KILL_DEFAULT_X_WM is set the WM is terminated after the started
# application finishes. Else FreeNX will wait for the WM to complete.
DEFAULT_X_WM="gdm"
# When a 'unix-default' session is requested by the client the user's X startup
# script will be run if pressent and executable, otherwise the default X
# session will be run.
# Depending on distribution USER_X_STARTUP_SCRIPT might be .Xclients, .xinitrc
# and .Xsession
# Depending on distribution DEFAULT_X_SESSION might be /etc/X11/xdm/Xsession,
# /etc/X11/Sessions/Xsession or /etc/X11/xinit/xinitrc
#USER_X_STARTUP_SCRIPT=.Xclients
DEFAULT_X_SESSION=/etc/X11/xdm/Xsession
# Linha acrescentada para utilização da interface gráfica “FLUXBOX”
COMMAND_START_FLUXBOX=fluxbox
##########################################################
# Misc directives
##########################################################
AGENT_FONT_SERVER="unix/:7100"
# General FreeNX directives
##########################################################
# The host name which is used by NX server. It's should be used if it's
# different than the default hostname (as returned by `hostname`)
SERVER_NAME="$(hostname)"
# The port number where local 'sshd' is listening.
SSHD_PORT=37775
##########################################################
# Authentication / Security directives
##########################################################
# This adds the passdb to the possible authentication methods
ENABLE_PASSDB_AUTHENTICATION="0"
# This adds SSH to the possible authentication methods. For it to work sshd
# must be set up at localhost accepting password authentication.
ENABLE_SSH_AUTHENTICATION="1"
# Require all users to be in the passdb, regardless of authentication method
ENABLE_USER_DB="0"
##########################################################
# Logging directives
##########################################################
# This directives controls the verbosity of the server-wide log.
# 0: No Logging
# 1: Errors
# 2: Warnings
# 3: Important information
# 4: Server - Client communication
# 5: Information
# 6: Debugging information
# 7: stderror of some applications
NX_LOG_LEVEL=7
# Before turning logging on, please make sure that NX_LOGFILE is
# writeable for the "nx" user
NX_LOGFILE=/var/log/nxserver.log
##########################################################
# Path directives
##########################################################
# The command binary for the default window manager. If set it is run when a
# 'unix-custom' session is requested by the NX Client and an application
# to run is specified. It defaults to empty (ie no WM is run).
# If KILL_DEFAULT_X_WM is set the WM is terminated after the started
# application finishes. Else FreeNX will wait for the WM to complete.
DEFAULT_X_WM="gdm"
# When a 'unix-default' session is requested by the client the user's X startup
# script will be run if pressent and executable, otherwise the default X
# session will be run.
# Depending on distribution USER_X_STARTUP_SCRIPT might be .Xclients, .xinitrc
# and .Xsession
# Depending on distribution DEFAULT_X_SESSION might be /etc/X11/xdm/Xsession,
# /etc/X11/Sessions/Xsession or /etc/X11/xinit/xinitrc
#USER_X_STARTUP_SCRIPT=.Xclients
DEFAULT_X_SESSION=/etc/X11/xdm/Xsession
# Linha acrescentada para utilização da interface gráfica “FLUXBOX”
COMMAND_START_FLUXBOX=fluxbox
##########################################################
# Misc directives
##########################################################
AGENT_FONT_SERVER="unix/:7100"
Configuração do SSH
Como o FreeNX utilizará uma porta diferente do padrão do ssh, é preciso executar essa alteração também no sshd. Para fazer essa alteração edite o arquivo /etc/ssh/sshd_config.
# vi /etc/ssh/sshd_config
Port 37775
Configuração do FluxBox
No FluBox houve uma alteração no menu para que as pessoas que acessassem remotamente essa máquina pudessem somente fazer acesso remoto, trocar a sua senha ou sair do sistema. Para que isso fosse realizado editamos o arquivo /usr/share/fluxbox/menu.
# vi /usr/share/fluxbox/menu
[begin] (NOME_DA_EMPRESA)
[exec] (Rdesktop) {tsclient}
[exec] (Troca de Senha) {xterm -iconic -e sh freenxpass}
[exit] (Exit)
[end]
[exec] (Rdesktop) {tsclient}
[exec] (Troca de Senha) {xterm -iconic -e sh freenxpass}
[exit] (Exit)
[end]
Para conseguir fazer o acesso remoto foi instalado um aplicativo chamado txclient:
# yum install tsclient
Já no sistema de troca de senha, foi criado um script para efetuar essa troca. Para que o script ficasse com um front end melhor foi utilizado um aplicativo chamado Xdialog.
#!/bin/bash
senha ()
{
SENHAOLD=$(/usr/bin/Xdialog --stdout \
--title "Troque a Senha" \
--insecure \
--passwordbox 'Informe a Senha Atual:' 0 0)
case $? in
1) exit ;;
esac
SENHA=$(/usr/bin/Xdialog --stdout \
--title "Troque a Senha" \
--insecure \
--passwordbox 'Informe a nova Senha. Minimo 6 caracteres' 0 0)
case $? in
1) exit ;;
esac
SENHACHECK=$(/usr/bin/Xdialog --stdout \
--title "Troque a Senha" \
--insecure \
--passwordbox 'Repita a nova Senha:' 0 0)
case $? in
1) exit ;;
esac
if [ "$SENHA" == "$SENHACHECK" ]
then
( echo $SENHAOLD ; echo $SENHA ; echo $SENHA ) | passwd 2>&- >&-
if [ $? -ne 0 ]
then
/usr/bin/Xdialog --title ERRO --msgbox ' Senha Atual Incorreta ou Senha Nova Fraca. Tente Novamente' 0 0
else
/usr/bin/Xdialog --title Nome_da_Empresa --msgbox 'Senha Alterada com Sucesso!' 0 0
exit
fi
else
/usr/bin/Xdialog --title ERRO --msgbox 'Erro na troca da senha: Senhas diferentes' 0 0
fi
}
while true
do
senha
done
senha ()
{
SENHAOLD=$(/usr/bin/Xdialog --stdout \
--title "Troque a Senha" \
--insecure \
--passwordbox 'Informe a Senha Atual:' 0 0)
case $? in
1) exit ;;
esac
SENHA=$(/usr/bin/Xdialog --stdout \
--title "Troque a Senha" \
--insecure \
--passwordbox 'Informe a nova Senha. Minimo 6 caracteres' 0 0)
case $? in
1) exit ;;
esac
SENHACHECK=$(/usr/bin/Xdialog --stdout \
--title "Troque a Senha" \
--insecure \
--passwordbox 'Repita a nova Senha:' 0 0)
case $? in
1) exit ;;
esac
if [ "$SENHA" == "$SENHACHECK" ]
then
( echo $SENHAOLD ; echo $SENHA ; echo $SENHA ) | passwd 2>&- >&-
if [ $? -ne 0 ]
then
/usr/bin/Xdialog --title ERRO --msgbox ' Senha Atual Incorreta ou Senha Nova Fraca. Tente Novamente' 0 0
else
/usr/bin/Xdialog --title Nome_da_Empresa --msgbox 'Senha Alterada com Sucesso!' 0 0
exit
fi
else
/usr/bin/Xdialog --title ERRO --msgbox 'Erro na troca da senha: Senhas diferentes' 0 0
fi
}
while true
do
senha
done
Otimo artigo!
No meu faz uma coisa estranha:
aparece "RSA key finguerprint is XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
are you sure you want to continue connecting? Yes or No"
clico em sim e aparece "connection completed" e depois "session startup failed"
Os detales de log são estes:
================================
NX> 203 NXSSH running with pid: 5067
NX> 285 Enabling check on switch command
NX> 285 Enabling skip of SSH config files
NX> 285 Setting the preferred NX options
NX> 200 Connected to address: 192.168.7.121 on port: 37775
NX> 211 The authenticity of host '192.168.7.121 (192.168.7.121)' can't be established.
RSA key fingerprint is XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX.
Are you sure you want to continue connecting (yes/no)?
Warning: Permanently added '192.168.7.121' (RSA) to the list of known hosts.
NX> 202 Authenticating user: nx
NX> 208 Using auth method: publickey
HELLO NXSERVER - Version 1.4.0-04 OS (GPL)
NX> 105 hello NXCLIENT - Version 1.4.0
NX> 134 Accepted protocol: 1.4.0
NX> 105 SET SHELL_MODE SHELL
NX> 105 SET AUTH_MODE PASSWORD
NX> 105 login
NX> 101 User: gil
NX> 102 Password:
NX> 103 Welcome to: beto user: gil
NX> 105 listsession --user="gil" --status="suspended,running" --geometry="1024x768x24+render" --type="unix-kde"
NX> 127 Sessions list of user 'gil' for reconnect:
Display Type Session ID Options Depth Screen Status Session Name
------- ---------------- -------------------------------- -------- ----- -------------- ----------- ------------------------------
NX> 148 Server capacity: not reached for user: gil
NX> 105 startsession --link="adsl" --backingstore="1" --nodelay="1" --encryption="1" --cache="8M" --images="32M" --media="0" --session="teste" --type="unix-kde" --cookie="fe00f41384ac43c6a19affcc2d7ff594" --geometry="800x600+112+65" --kbtype="pc102/br" --screeninfo="800x600x24+render"
NX> 1000 NXNODE - Version 1.4.0-04 OS (GPL)
NX> 700 Session id: beto-1000-53227E96CAEC5585B8966A124B0AF408
NX> 705 Session display: 1000
NX> 703 Session type: unix-kde
NX> 701 Proxy cookie: f5502a0c36db1c1fb2a8415c11b77491
NX> 702 Proxy IP: 127.0.0.1
NX> 706 Agent cookie: fe00f41384ac43c6a19affcc2d7ff594
NX> 704 Session cache: unix-kde
NX> 707 SSL tunneling: 1
NX> 105 /usr/lib/nx/nxserver: line 1035: 5230 Terminado ( sleep 10; exit 1 )
NX> 504 Session startup failed.
NX> 1004 Error: nxagent failed to start with: Unrecognized option: 1
NX> 1001 Bye.
Killed by signal 15.
==================================