Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Perform AES256 encryption on a string using command

Answer:

To encrypt a string using AES256, you can use the openssl tool.

# echo -n 'apple' | openssl enc -aes256 -k password -nosalt -iv 0 -a -p

key=1F3870BE274F6C49B3E31A0C6728957F0628DEF3179C824405825F85F5527096
iv =00000000000000000000000000000000
PMcE/8RE+RLRlQWT5tlLWA==

Check for the number of connection from a particular IP address

Answer:

You can check the total number of connections from a particular IP address:

# netstat -ntu | awk '{print $5}'| cut -d: -f1 | sort | uniq -c | sort -nr | more

It will give something like:

25 192.168.1.2
13 192.168.1.3
..

Simple file encryption with OpenSSL

Answer:

You have a single file (input.txt), and you want to encrypt it with a password, it is easy with OpenSSL.

# openssl aes-128-cbc -salt -in input.txt-out input.aes

Enter the password twice.

When you want to decrypt it, use the command.

# openssl aes-128-cbc -d -salt -in input.aes -out output.txt

Add a user that can gain root privileges in Ubuntu

Answer:

You have created a user, and now you want to make this user (e.g. peter as an example) can gain root privileges.

Firstly, check your /etc/sudoers file

# sudo cat /etc/sudoers

You might found the following lines

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
john ALL=(ALL) ALL

Method 1

If you have the line %admin ALL=(ALL) ALL, then you can add the user (e.g peter) to the admin group using the command:

# sudo usermod -g admin peter

Method 2

Or you can edit the file /etc/sudoers to add your account manually

# sudo visudo

Append peter ALL=(ALL) ALL at the end..

%admin ALL=(ALL) ALL
john ALL=(ALL) ALL
peter ALL=(ALL) ALL

How to check failed login attempt in Ubuntu

Answer:

Every login attempts are logged in the file /var/log/auth.log in Ubuntu.

To check failed login attempt(s),

E.g.

# grep 'Failed password' /var/log/auth.log

Jan 31 14:00:27 localhost sshd[16141]: Failed password...
Jan 31 14:00:46 localhost sshd[16141]: Failed password...
Jan 31 14:00:49 localhost sshd[16141]: Failed password...