Giter Club home page Giter Club logo

ssh-control-hours's Introduction

ssh-control-hours

A stack of procedures for register ssh login/logout activities. There is no code here. Its just a recipe to follow. It used to work well, but there is no warranty.

What is the purpose?

The purpose is exclusively personal (read: workaround from a lazy guy to other lazy ones). Everybody knows how hard it is to keep track of daily activities. It becomes much worse when you have multiple customers, projects and so on.

What does it do?

Basically the tool works sending to a file 2 registers: ssh login and logout.

No matter the login method you are using (single user such as "centos" for example). It sends an envvar thought the ssh connection. This var contains your id. The remote environment receives it and save to a log file that will be sent to a remote storage when you get out of the server. Quite straight forward

How do I make it work here?

On your machine, add the follow value on ~/.ssh/config:

SendEnv GETUP_EA
  • The value can be whatever you want. You will consume it. Make it clear for you.

Add it on your ~/.bashrc:

export GETUP_EA=edilson.azevedo

Update your env:

source  ~/.bashrc

On the server side, add the following line on /etc/ssh/sshd_config and restart the ssh server:

AcceptEnv LANG LC_* GETUP*

Yet on the server, add these lines on ~/.bashrc:

getupreg() {
    curl -s --output /dev/null --upload-file "$1" http://transfer.easycloud.guru:8080/$(basename "$1") | tee /dev/null;
}
alias getupreg=getupreg

Important notes:

  • Change the bashrc file of the user that you are used to use to login on the server, ok?
  • The transfer.easycloud.guru is a personal storage service based on a project called transfer.sh (https://github.com/dutchcoders/transfer.sh). Again: you can use what you want!

Last but not least, yet on the server side, add these lines to ~/.profile

TIME=$(TZ=America/Sao_Paulo date +%Y%m%d.%H:%M)
RANDOM=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
LOGG=/tmp/$GETUP_EA-$RANDOM-$HOSTNAME.temp

echo "USER $GETUP_EA LOGGED AT $TIME" >> $LOGG
function onexit { echo "USER $GETUP_EA LOGOUT AT $(TZ=America/Sao_Paulo date +%Y%m%d.%H:%M)" >> $LOGG; getupreg $LOGG ; rm -f $LOGG ; }; trap onexit EXIT

Update the env:

source  ~/.bashrc && source ~/.profile

Done!

Output example:

USER edilson.azevedo LOGGED AT 20201203.23:10
USER edilson.azevedo LOGOUT AT 20201204.04:39

It can be transitive (if you are using a bastion host or proxy or whatever. The key is keep sending the ssh env across the servers. Just it.

Cheers!

ssh-control-hours's People

Contributors

eazeved0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.