Pense Bête

 

 

1 How to create user account on ubuntu machine :

2 How to send mail with mail command

2.1 Configuration

2.2 Sending mail

2.3 Sending mail through crontab

3 How to get OS version

4 How to access to internet via command line:

5 How to activate graphics on server machine :

6 How to know execution result :

7 How to search uid from name

8 How to search mail from UID

9 What is the syntax of a cronjob using crontab

10 How to generate a complex password

11 How delete lignes from file

12 How to setup cvs on the client side

13 How to host a new sub-site using apache2

14 How to search file containing a text

15 How to show vg

16 How to show lv

17 How to access a ssh server without being asked for a password

17.1 In the Client :

17.2 In the ServerSSH :

 

How to create user account on ubuntu machine :

$ sudo useradd -m -s /bin/bash -G admin <user_name>
$sud passwd <user_name>

 

How to send mail with mail command

Install mail commande : sudo apt-get install mail

Configuration

Verify if you have a file .mailrc in sender home directory. If not, create it and add this line :

alias admin adress1@domain adress2@domain adress3@domain ...

sudo newaliases

Sending mail

cat file | /usr/bin/mail -s "Subject" admin -c user@domain -- -r webmaster@domain

  • -s: mail subject
  • admin: recipient group
  • -c : Send carbon copies to list of users
  • -- -r: change a default sender to webmaster@domain. Otherwhise, a user who launchs command will be a default sender.

A first part of command is a content of mail.

Sending mail through crontab

38 16 * * * script 2>&1 | /usr/bin/mail -s "Backup Report" admin -- -r user

The report sent to group admin from user@domain will contain stderr and stdout.

How to get OS version

$lsb_release -a

How to access to internet via command line:

$export http_proxy="http://login:passwd@squid.domain:3128"
$export no_proxy="domain"

How to activate graphics on server machine :

1. install xauth on the server side
2. access to the server using ssh -X

How to know execution result :

$commande to execute
result
$echo $?

if result is 0 : command has been succefully executed

How to search uid from name

$ldapsearch -x -h openldap.domain -b "ou=people,dc=scom,dc=domain" displayName="<user name>"

How to search mail from UID

$ldapsearch -x -h openldap.domain -b "ou=people,dc=scom,dc=domain" uid=gxxxxxx

What is the syntax of a cronjob using crontab

Ce champ suit la syntaxe de cron (avec des différences mineures). Chaque ligne consiste en 5 champs séparés par des TABs ou des espaces :

MINUTES HEURES JOURMOIS MOIS JOURSEMAINE

MINUTES Les minutes dans une heure (0-59) HEURES Les heures dans une journée (0-23) JOURMOIS Le jour dans un mois (1-31) MOIS Le mois (1-12) JOURSEMAINE Le jour de la semaine (0-7) où 0 et 7 représentent le dimanche

Pour spécifier des valeurs multiples pour un champ, utilisez les opérateurs suivants. Par ordre de précédence :

   * '*' représente l'ensemble des valeurs possibles.
* 'M-N' représente une liste bornée, telle que "1-5"
* 'M-N/X' ou '*/X' permettent de spécifier des sauts de valeur X dans la liste. Par exemple, "*/15" dans le champ MINUTES est équivalent à "0,15,30,45" et "1-6/2" à "1,3,5"
* 'A,B,...,Z' permet de spécifier des valeurs multiples, comme "0,30" ou "1,3,5"

Les lignes vides et les lignes qui commencent par '#' seront considérées comme des commentaires et ignorées.

Par ailleurs, les mots-clefs '@yearly', '@annually', '@monthly', '@weekly', '@daily', '@midnight' et '@hourly' sont supportés. Exemples

# toutes les minutes
* * * * *
# toutes les 5 minutes après l'heure
5 * * * *

How to generate a complex password

There are many ways to do that (including command line tools in linux)

a simple way is to generate a password using the following URL : http://www.zerobug.fr/Generateur_mots_de_passe.php

How delete lignes from file

cat file|grep -v EXP > file_result
EXP : lignes containing EXP expression
file_result : a result file without lignes deleted

How to setup cvs on the client side

insert the following expression in one of the environment files like ~/.bashrc

CVSROOT=:pserver:<username>@<computername>:<repository>

How to host a new sub-site using apache2

to host a directory (for example : /usr/local/samba) using apache2 we must edit /etc/apache2/sites-enabled/000-default and add the following alias :

Alias /

/usr/local/samba

and then be sure that the owner and the group of the directory are www-data

chown -R www-data:www-data /usr/local/samba

How to search file containing a text

$ grep -rin "text" <root_search>
# r : recursive
# i : ignore case
# n : prints line number

How to show vg

$ sudo vgdisplay

How to show lv

$ sudo lvdisplay

How to access a ssh server without being asked for a password

An alternate way of accessing a ssh server with login/password couple, is to use public ID of the ssh client at the server side. This is useful for shell scripting

In the Client :

Create the public keys

user@client$ ssh-keygen

example

wissem@wissem-desktop:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/
wissem/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/
wissem/.ssh/id_rsa.
Your public key has been saved in /home/
wissem/.ssh/id_rsa.pub.
The key fingerprint is:
2a:f3:14:81:5d:fd:85:46:78:08:ee:79:13:6a:07:c3 wissem@wissem-desktop
wissem@wissem-desktop:~$

2/ Copy the public id in the Server

user@client$ scp .ssh/id_rsa.pub wissemadmin@server:/tmp

In the ServerSSH :

copy the public_id of client in /root/.ssh/authorized_keys

root@server# mkdir /root/.ssh
root@server# cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys

 

 

Hope This Helps!

Wissem MEDIOUNI


Écrire commentaire

Commentaires: 32
  • #1

    Juicers Reviews (samedi, 20 avril 2013 23:32)

    This is an excellent blog post! Thank you for sharing with us!

  • #2

    gBqsPxAZ (mardi, 04 octobre 2022)

    20

  • #3

    gBqsPxAZ (mardi, 04 octobre 2022 15:40)

    20

  • #4

    gBqsPxAZ (mardi, 04 octobre 2022 15:41)

    20

  • #5

    gBqsPxAZ (mardi, 04 octobre 2022 15:41)

    20

  • #6

    gBqsPxAZ (mardi, 04 octobre 2022 15:42)

    20

  • #7

    gBqsPxAZ (mardi, 04 octobre 2022 15:42)

    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

  • #8

    gBqsPxAZ (mardi, 04 octobre 2022 15:43)

    EsJ6c7LK'; waitfor delay '0:0:15' --

  • #9

    gBqsPxAZ (mardi, 04 octobre 2022 15:43)

    EkbHNrL7') OR 361=(SELECT 361 FROM PG_SLEEP(15))--

  • #10

    gBqsPxAZ (mardi, 04 octobre 2022 15:44)

    20

  • #11

    gBqsPxAZ (mardi, 04 octobre 2022 15:44)

    20

  • #12

    gBqsPxAZ (mardi, 04 octobre 2022 15:45)

    20

  • #13

    gBqsPxAZ (mardi, 04 octobre 2022 15:46)

    20

  • #14

    gBqsPxAZ (mardi, 04 octobre 2022 15:46)

    20

  • #15

    gBqsPxAZ (mardi, 04 octobre 2022 15:47)

    20

  • #16

    gBqsPxAZ (mardi, 04 octobre 2022 15:47)

    20

  • #17

    gBqsPxAZ (mardi, 04 octobre 2022 15:49)

    20

  • #18

    1 waitfor delay '0:0:15' -- (mardi, 04 octobre 2022 15:50)

    20

  • #19

    ps1Mts56')) OR 559=(SELECT 559 FROM PG_SLEEP(15))-- (mardi, 04 octobre 2022 15:50)

    20

  • #20

    gBqsPxAZ (mardi, 04 octobre 2022 15:51)

    20

  • #21

    gBqsPxAZ (mardi, 04 octobre 2022 15:51)

    20

  • #22

    gBqsPxAZ (mardi, 04 octobre 2022 15:52)

    20

  • #23

    gBqsPxAZ (mardi, 04 octobre 2022 15:52)

    20

  • #24

    gBqsPxAZ (mardi, 04 octobre 2022 15:53)

    20

  • #25

    gBqsPxAZ (mardi, 04 octobre 2022 15:54)

    20

  • #26

    gBqsPxAZ (mardi, 04 octobre 2022 15:54)

    20

  • #27

    gBqsPxAZ (mardi, 04 octobre 2022 15:55)

    20

  • #28

    gBqsPxAZ (mardi, 04 octobre 2022 15:55)

    20

  • #29

    gBqsPxAZ (mardi, 04 octobre 2022 15:56)

    20

  • #30

    gBqsPxAZ (mardi, 04 octobre 2022 16:06)

    20

  • #31

    lxbfYeaa (mardi, 05 décembre 2023 05:58)

    20

  • #32

    lxbfYeaa (mardi, 05 décembre 2023 05:59)

    20