Wednesday, August 10, 2011

Authentication with PublicKeys

Ce document explique les différentes étapes pour mettre en place l'authentification par clef
publiques.

Les avantages tirés sont pluriel:

- Evite la propagation des mots de passe root,
- Evite l'utilisation d'un mot de passe trop simple, souvent utilisé pour ne
  pas l'oublier, et car les connexion sont nombreuses dans une journée,
- Ajoute une granularité dans la mise en place de la sécurité,
- Facilite le travail quotidien, par des connexions plus rapides.


I - Coté client

1.1 Création des paires de clef privée/publiques cliente.

Les clef sont crée avec la commande `ssh-keygen', il vous sera demander un nom
de fichier, acceptez celui par défaut, puis une pass-phrase (Le mot de passe),
veillez à en choisir un assé long, une phrase serait l'idéal.

    $ ssh-keygen -t rsa1 # SSH1
    $ ssh-keygen -t rsa  # SSH2
    $ ssh-keygen -t dsa  # SSH2

1.2. L'agent ssh

Maintenant pour éviter d'avoir à taper notre passphrase à chaque connexion,
nous allons utiliser la commande `ssh-agent'. Grâce à lui, nous n'aurons qu'à
taper notre passphrase qu'une fois au début de la journée:

    $ eval $(ssh-agent)
    Agent pid 2592


puis il nous faut ajouter nos clef.
Rem: si vous avez choisi la même passphrase pour toutes les trois clef, elle
ne vous sera demandée qu'une seulle fois:

    $ ssh-add
    Enter passphrase for /home/YE01389/.ssh/id_rsa:
    Identity added: /home/YE01389/.ssh/id_rsa (/home/YE01389/.ssh/id_rsa)
    Identity added: /home/YE01389/.ssh/id_dsa (/home/YE01389/.ssh/id_dsa)
    Identity added: /home/YE01389/.ssh/identity (YE01389@CTIRE333)


On peut verifier qu'elles ont bien été prises en compte:

    $ ssh-add -l
    2048 9a:08:b9:b8:e6:25:bd:6c:4e:8c:25:13:2e:36:62:97 YE01389@CTIRE333 (RSA1)
    2048 5b:7f:cd:96:2c:f4:41:66:1a:83:4b:ff:ad:89:85:42 /home/YE01389/.ssh/id_rsa (RSA)
    2048 9a:e0:e3:af:b8:65:a1:c6:06:2c:80:8e:8a:1a:c9:30 /home/YE01389/.ssh/id_dsa (DSA)


Coté client c'est Ok.

II - Coté serveur

passons sur l'installation du serveur ssh, et concentrons nous sur le
spécifique pour accepter l'Authentification par Clef publiques.


2.1 La configuration du serveur:

Les options suivante doivent être présentes dans le fichier de conf :

/opt/ssh/etc/sshd_config:

    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile    .ssh/authorized_keys

    StrictModes no # Si les droits sur le $HOME ne sont pas 0700


puis pour recharger la config :

$ kill -1 $(cat /var/run/sshd.pid)

2.2 Ajout des clef.

Pour que la connexion soit possible, il nous faut rajouter la(les) clef
publique dans le fichier d'authorization:

Après avoir copié sur le serveur la clef publique (DSA):
   
    $ cat id_dsa.pub >>$HOME/.ssh/authorized_keys

III - Test de connexion

    $ ssh unix@support
    MMSQYY00 [HP Release B.11.00]
    Last   successful login for unix: Tue Sep 20 15:12:54 MET-1METDST 2005 on pts/43
    Last unsuccessful login for unix: Tue Sep 20 09:58:07 MET-1METDST 2005 on pts/tp
    Last login: Mon Aug 29 20:19:36 2005 from VPNRE1NT.arpege
    You have mail.
   
Dans les logs:

    Sep 20 15:17:32 mmsqyy00 sshd[24103]: Accepted publickey for unix from 126.52.3.102 port 3546 ssh2



Thursday, April 14, 2011

SSH: creation de tunnel via fichier de config

Petit truck:

Mise en place d'un tunnel via ssh:

dans $HOME/.ssh/config:

--cut--------8<------------------------
Host smtp-forwarding
    Hostname mmseyy00
    User unix
    LocalForward 25 localhost:25
    SendEnv *
--cut--------8<------------------------

Ouverture du tunnel pendant 60 secondes:

$ ssh -fn smtp-forwarding sleep 60

explication:
    -f : fork to background
    -n : redirect stdin to /dev/null
    smtp-forwarding : appel de l'hote
    sleep 60  : commande pour laisser ouvert le tunnel

 

Tuesday, March 29, 2011

Juniper: How to reset to factory default a SRX

SRX: different way to reset to factory-default

so, you may know the standard way, the teached way, i mean pushing during 15 secondes the reset micro-button. This method work fine on J-series, but not on somes SRX, not on MX series...

so, i will try to write down somes of the method i used to reset to factory default the juniperdevices.

Factory Default, really ?

First, i need, we need to define what exactly is a factory-default reset. Is it just putting back the configuration to its initial state ? just this ? and what do you do with all the logs files ? the debug files ? the configurations saved ?

It is a security breach to lets everything inside the box, so putting a device back to the factory-default state is not just the configuration, it is mainly everything, even the ssh key: we want to generate a new one, because the old is not trusted anymore.

Lets start.

Loose the root password.
the common process is the boot in single user mode:

at the boot, after the u-boot, when the bootstrap is loaded, you can hit the spacebar:
 

Hit [Enter] to boot immediately, or space bar for command prompt.
 
so you should see:

FreeBSD/MIPS U-Boot bootstrap loader, Revision 1.5
(builder@ormonth.juniper.net, Fri Oct  9 10:55:15 UTC 2009)
Memory: 1024MB
[0]Booting from nand-flash slice 2
Un-Protected 1 sectors
writing to flash...
Protected 1 sectors
Loading /boot/defaults/loader.conf
/kernel data=0x97d8ac+0xd70d0 syms=[0x4+0x79c50+0x4+0xadd2e]
 

Hit [Enter] to boot immediately, or space bar for command prompt.


Loader>
Loader> watchdog disable
Loader> boot –s
root@host% cli
root@host> edit
root@host# set system root-authentication plain-text-password
New password: juniper1
Retype new password: juniper1
root@host# commit
commit complete
root@host# run request system reboot
Reboot the system ? [yes,no] (no) yes

Root passwd on SRX Platform
on SRX Branch platforms and JUNOS 10.0R1 or later, there is a condition in which the password recovery process does not work. After issuing recovery command, system never reaches the point where root password can be changed. System reboots instead. So we need to apply a specific procedure to recover root password for SRX Branch devices running on Junos version 10.0R1 or later. This involves disabling watchdog functionality to allow for system to properly boot into single-user mode.

 

Hit [Enter] to boot immediately, or space bar for command prompt.
Booting [kernel] in 9 seconds...
Loader>
Loader> watchdog disable
Loader> boot –s

change the root passwd, reboot, and don't forget to enable the watchdog, and boot in normal mode

 

Hit [Enter] to boot immediately, or space bar for command prompt.
Booting [kernel] in 9 seconds...
Loader>
Loader> watchdog enable
Loader> boot

Damned, HA is enabled

If you're lucky, your device is in master mode, so you can just diasble the HA:

{primary:node1}
root@titi> set chassis cluster disable reboot
Successfully disabled chassis cluster. Going to reboot now

But if you're not, lucky i mean, your device is on hold, and you're trying to reset the root passwd on single user mode, but you can't:

Starting CLI ...
{hold:node1}
root> edit
warning: Clustering enabled; using private edit
error: shared configuration database modified

Please temporarily use 'configure shared' to commit
outstanding changes in the shared database, exit,
and return to configuration mode using 'configure'

{hold:node1}
root>

Ok, so deleting all the interfaces in the configuration seems to allow me to finally commit.

Then reboot and disable the cluster :

root@>set chassis cluster disable

TRUE Factory default

so, to delete all the logs, the dumps, the rollback, the root password in the factory-default config, and even to reset the host ssh key, you need to zeroize the device:

root> request system zeroize
warning: System will be rebooted and may not boot without configuration
Erase all data, including configuration and log files? [yes,no] (no) yes

warning: zeroizing re0

....
....

Local package initialization:.
starting local daemons:.
kern.securelevel: -1 -> 1
Creating JAIL MFS partition...
JAIL MFS partition created

Database Initialization Utility
RDM Embedded 7 [04-Aug-2006] http://www.birdstep.com
Copyright (c) 1992-2006 Birdstep Technology, Inc.  All Rights Reserved.

secdb initialized

Database Initialization Utility
RDM Embedded 7 [04-Aug-2006] http://www.birdstep.com
Copyright (c) 1992-2006 Birdstep Technology, Inc.  All Rights Reserved.

dfacache initialized

Boot media /dev/da0 has dual root support
** /dev/da0s2a
FILE SYSTEM CLEAN; SKIPPING CHECKS
clean, 58564 free (44 frags, 7315 blocks, 0.0% fragmentation)
Tue Mar 29 14:41:31 UTC 2011

Amnesiac (ttyu0)

login: root

--- JUNOS 10.2R3.10 built 2010-10-16 20:36:59 UTC

root@%



EX series TIPS
LINECARD
sometimes, your switch can be in the linecard state, which means that there is no routing engine running in it. So you first need to enable one.
Example off linecard prompt:
root@:LC:0% cli
{linecard:0}
root>
To enabled the RE mode:

root> request virtual-chassis reactivate

This member split from a virtual chassis. Please make sure that no active
switch belonging to this virtual chassis has conflicting configuration.

Do you want to continue ? [yes,no] (no) yes

{linecard:0}
root>
Amnesiac (ttyu0)

login:
Amnesiac (ttyu0)

login:
Amnesiac (ttyu0)

root@:RE:0%      

so now you can configure the switch.

 

MEMBER-ID is not 0
so, if your switch was member of a virtual-chassis, and it member-id was from 1 to 9, you can't let it as is, because all your interfafce configuration that belongs to ge-0/0/0-47 won't be enabled...
So you need to renumber your device:

{master:1}
root> request virtual-chassis renumber new-member-id 0 member-id 1

Note: change 1 with your actual id.

prompt changed:

{master:0}
root>

That's all for the moment.

Tuesday, March 8, 2011

lvextend

Howto quickly extend a lvm partition

First, verify you have enough space available.

# pvs
  PV                VG       Fmt  Attr PSize   PFree
  /dev/block/104:17 lebowski lvm2 a-   273,45g 142,77g
  /dev/block/104:5  lebowski lvm2 a-   135,42g      0

 So, here we have about 142 Go free.

 Next, extend the logical volume, here i added 20 Go

# lvextend -L+20G /dev/lebowski/home
  Extending logical volume home to 251,54 GiB
  Logical volume home successfully resized

Finally, resize the partition to fit the physical available space:

# resize2fs /dev/lebowski/home
resize2fs 1.41.12 (17-May-2010)
Le système de fichiers de /dev/lebowski/home est monté sur /home ; le changement de taille doit être effectué en ligne
old desc_blocks = 15, new_desc_blocks = 16
En train d'effectuer un changement de taille en ligne de /dev/lebowski/home vers 65939456 (4k) blocs.
Le système de fichiers /dev/lebowski/home a maintenant une taille de 65939456 blocs.


Checking:

# df -h /home/
Sys. de fichiers    Taille  Uti. Disp. Uti% Monté sur
/dev/mapper/lebowski-home
                      248G  217G   19G  93% /home