<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es">
		<id>https://wiki.gacq.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Newacct</id>
		<title>gacq wiki - Contribuciones del usuario [es]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.gacq.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Newacct"/>
		<link rel="alternate" type="text/html" href="https://wiki.gacq.com/index.php/Especial:Contribuciones/Newacct"/>
		<updated>2026-04-09T12:35:01Z</updated>
		<subtitle>Contribuciones del usuario</subtitle>
		<generator>MediaWiki 1.29.2</generator>

	<entry>
		<id>https://wiki.gacq.com/index.php?title=SSH&amp;diff=3017</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="https://wiki.gacq.com/index.php?title=SSH&amp;diff=3017"/>
				<updated>2010-05-27T09:37:57Z</updated>
		
		<summary type="html">&lt;p&gt;Newacct: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= General =&lt;br /&gt;
== Abrir una aplicacion X remota ==&lt;br /&gt;
=== encontré cómo hacer que te puedas meter en tu casa y abrir una aplicación X desde una red privada con salida con NAT ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
1) xhost +&lt;br /&gt;
&lt;br /&gt;
2) ssh -X -l sshuser pc.micasa.net&lt;br /&gt;
&lt;br /&gt;
3) xclock  (debe funcionar)&lt;br /&gt;
&lt;br /&gt;
4) El problema viene cuando vas a ejecutar algo de otro usuario porque haciendo su, no puede setear el DISPLAY adecuadamente, pero se resuelve así desde el usuario sshuser:&lt;br /&gt;
&lt;br /&gt;
	gksu -g -u root /usr/X11R6/bin/xclock&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
te pide la password del usuario y nada más para ejecutar la aplicación.&lt;br /&gt;
La performance, es otro tema.&lt;br /&gt;
&lt;br /&gt;
== ssh sin password (Rapido) ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# Si el archivo ~/.ssh/authorized_keys remoto existe&lt;br /&gt;
cat ~/.ssh/id_rsa.pub | ssh remoteuser@remotehost 'cat - &amp;gt;&amp;gt; ~/.ssh/authorized_keys'&lt;br /&gt;
# Si el archivo ~/.ssh/authorized_keys remoto NO existe&lt;br /&gt;
cat ~/.ssh/id_rsa.pub | ssh remoteuser@remotehost 'cat - &amp;gt; ~/.ssh/authorized_keys'&lt;br /&gt;
# Opcional, qu enadie pueda leer el archivo con las claves publicas&lt;br /&gt;
ssh remoteuser@remotehost 'chmod 700 ~/.ssh ; chmod 600 ~/.ssh/authorized_keys'	&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ssh sin password (Explicado) ==&lt;br /&gt;
&lt;br /&gt;
This document explains how to authenticate through &amp;lt;tt&amp;gt;ssh&amp;lt;/tt&amp;gt; to multiple&lt;br /&gt;
machines without having to enter your password each time.&lt;br /&gt;
&lt;br /&gt;
This is very useful when you are constantly invoking &amp;lt;tt&amp;gt;ssh&amp;lt;/tt&amp;gt; or&lt;br /&gt;
copying files with &amp;lt;tt&amp;gt;scp&amp;lt;/tt&amp;gt;.  It also allows you to make &amp;lt;tt&amp;gt;scp&amp;lt;/tt&amp;gt; transfers&lt;br /&gt;
automatically (using a cron job in one of the machines).&lt;br /&gt;
&lt;br /&gt;
Check the&lt;br /&gt;
[[ssh watchdog]] for an example of something you could accomplish with&lt;br /&gt;
this.&lt;br /&gt;
&lt;br /&gt;
== Generate a public/private key pair ==&lt;br /&gt;
&lt;br /&gt;
Run &amp;lt;tt&amp;gt;ssh-keygen -t rsa&amp;lt;/tt&amp;gt; on your host machine&lt;br /&gt;
(the one you'll be connecting from).  Use the default settings&lt;br /&gt;
and an empty passphrase:&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen -t rsa&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/home/user/.ssh/id_rsa): &lt;br /&gt;
 Enter passphrase (empty for no passphrase): &lt;br /&gt;
 Enter same passphrase again: &lt;br /&gt;
 Your identification has been saved in /home/user/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /home/user/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 90:02:83:45:8b:3b:37:72:d4:0a:7a:5f:8e:1e:7a:38&lt;br /&gt;
&lt;br /&gt;
This should generate the &amp;lt;tt&amp;gt;id_rsa.pub&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;id_rsa&amp;lt;/tt&amp;gt;&lt;br /&gt;
keys in your &amp;lt;tt&amp;gt;~/.ssh&amp;lt;/tt&amp;gt; directory:&lt;br /&gt;
&lt;br /&gt;
 -rw-r--r--   1 user group 221 Apr 10 00:08 id_rsa.pub&lt;br /&gt;
 -rw-------   1 user group 883 Apr 10 00:08 id_rsa&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;id_rsa&amp;lt;/tt&amp;gt; file contains your private key.  As such, it&lt;br /&gt;
will only be readable by you (permissions mode 600).  The &amp;lt;tt&amp;gt;id_rsa.pub&amp;lt;/tt&amp;gt;&lt;br /&gt;
file contains its corresponding public key.&lt;br /&gt;
&lt;br /&gt;
== Add the public key to the remote machine ==&lt;br /&gt;
&lt;br /&gt;
You'll need to append your public key to the &amp;lt;tt&amp;gt;~/.ssh/authorized_keys&amp;lt;/tt&amp;gt;&lt;br /&gt;
file in the remote machine.&lt;br /&gt;
&lt;br /&gt;
You can do this with the following command:&lt;br /&gt;
&lt;br /&gt;
 $ ssh user@remote cat \&amp;gt;\&amp;gt; ~/.ssh/authorized_keys &amp;lt;~/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
If the &amp;lt;tt&amp;gt;~/.ssh&amp;lt;/tt&amp;gt; directory does not exist in the&lt;br /&gt;
remote machine, you'll need to create it.&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
You can read &amp;lt;tt&amp;gt;ssh-keygen(1)&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ssh(1)&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ssh-agent(1)&amp;lt;/tt&amp;gt;&lt;br /&gt;
for more information.&lt;br /&gt;
&lt;br /&gt;
Specifically, you might want to use a non-empty passphrase in combination with &lt;br /&gt;
&amp;lt;tt&amp;gt;ssh-agent(1)&amp;lt;/tt&amp;gt;: this will require you to give your password to&lt;br /&gt;
&amp;lt;tt&amp;gt;ssh-agent&amp;lt;/tt&amp;gt; once in order to be able to use your private key.&lt;br /&gt;
&lt;br /&gt;
== OTRO: SSH Nopasswd login ==&lt;br /&gt;
=== Local ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
cd .ssh&lt;br /&gt;
ssh-keygen -b 1024 -f identity -P '' -t dsa&lt;br /&gt;
scp identity.pub gacq@192.168.0.20:&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Remoto ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
cat identity.pub &amp;gt;&amp;gt; .ssh/authorized_keys&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=SSH Port forwarding=&lt;br /&gt;
;Login to a NAT firewalled server from Internet&lt;br /&gt;
==Base commands==&lt;br /&gt;
;At internal host&lt;br /&gt;
 ssh -N -R 2222:localhost:22 user@gacq.com&lt;br /&gt;
&lt;br /&gt;
;At localhost&lt;br /&gt;
 ssh -p 2222 root@localhost&lt;br /&gt;
&lt;br /&gt;
==Script to maintain the forward UP==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
CONNECT='ssh -N -R 22222:localhost:22 user@gacq.com'&lt;br /&gt;
USER=gacq&lt;br /&gt;
&lt;br /&gt;
while [ 1 ]&lt;br /&gt;
do&lt;br /&gt;
  SSH_RUNNING=`ps -eo args | grep &amp;quot;$CONNECT&amp;quot; | grep -v grep | wc -l`&lt;br /&gt;
&lt;br /&gt;
  # Check if there are any ssh forward running&lt;br /&gt;
  if [ $SSH_RUNNING -gt 0 ]&lt;br /&gt;
  then&lt;br /&gt;
    # Check if there are any user connected from localhost&lt;br /&gt;
    if [ `who | grep $USER | grep localhost | grep pts | wc -l` -eq 0 ]&lt;br /&gt;
    then&lt;br /&gt;
      # If not kill ssh - This is to prevent crashed conenections&lt;br /&gt;
      SSH_PID=`ps -ef | grep &amp;quot;$CONNECT&amp;quot; | grep -v grep | head -1 | awk '{print $2}'`&lt;br /&gt;
      kill -15 $SSH_PID&lt;br /&gt;
      sleep 1&lt;br /&gt;
      nohup $CONNECT &amp;amp;&lt;br /&gt;
    fi&lt;br /&gt;
  else&lt;br /&gt;
    # If not connected reconnect&lt;br /&gt;
    nohup $CONNECT &amp;amp;&lt;br /&gt;
  fi&lt;br /&gt;
&lt;br /&gt;
  sleep 120&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Protegiendonos de ataques SSH =&lt;br /&gt;
La mejor opcion es cambiar el puerto por defecto, si esto no es posible tenemos:&lt;br /&gt;
*[http://fail2ban.sourceforge.net/ Fail2Ban (Tambien sirve para los logs del apache]&lt;br /&gt;
*[http://daemonshield.sourceforge.net/ Daemon Shield]&lt;br /&gt;
*[http://denyhosts.sourceforge.net/ DenyHosts]&lt;/div&gt;</summary>
		<author><name>Newacct</name></author>	</entry>

	</feed>