Tuesday, 16 August 2016

Passwordless SSH keygen login and Bash History Logging

 Password-less SSH keygen login::

Server :

# ssh-keygen -t rsa

This will generate 2 keys under the home directory.
1. /home/linuxgeeknotes/.ssh/id_rsa (private key)
2. /home/linuxgeeknotes/.ssh/id_rsa.pub (public key)

Client :

Copy the public key in  /home/linuxgeeknotes/.ssh/id_rsa.pub to the client's home directory who want to login with password.

# ssh-copy-id root@
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@'s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@'"
and check to make sure that only the key(s) you wanted were added.

You should be able to login without password now.

Disable ssh root login and allow login for a particular user only::
 Edit /etc/ssh/sshd_config and add the entries

PermitRootLogin no
AllowUsers user1
DenyUsers user2

Edit vi /etc/sudoers or visudo and add entry for user1 before logging out.

user1  ALL=(ALL)       ALL

Save and restart ssh.service

Now only user1 will be allowed to login to the server via ssh.

Bash History Logging::
Usually when multiple terminals are opened simultaneously, the bash history will be over written by the last closed session.

Install psacct utility for process accounting. By default it get installed with GUI installation.
If you have done minimal installation then
# yum install psacct
# systemctl start psacct

The psacct  utilities for monitoring process,  activities are ac, lastcomm, accton and sa.

ac --> command displays statistics about how long users have been logged on.
lastcomm --> command displays information about previous executed commands.
accton --> command turns process accounting on or off.
sa --> command summarizes information about previously executed commands.

# ac -p    --> Prints connected time in hours by each user
# lastcomm --user linuxgeeknotes
# lastcomm --command  rm

No comments:

Post a Comment