Find Who Is Logged in by Ssh Key Fingerprint
Old debian based OS
$ grep 'Accepted publickey' /var/log/auth.log
...
Oct 12 07:09:05 <hostname> sshd[54321]: Accepted publickey for <username> from <ip> port 12345 ssh2: ED25519 00:00:00:00:00:00:00:00:00:00:00:00:00:00
...
sudo -i -u username sh -c 'cat ~/.ssh/authorized_keys | sed "s/^/localhost /" > /tmp/authorized_keys'
ssh-keygen -l -f /tmp/authorized_keys | grep 00:00:00:00:00:00:00:00:00:00:00:00:00:00
256 00:00:00:00:00:00:00:00:00:00:00:00:00:00 user@example.com (ED25519)
Modern RHEL/Debian based OS
$ journalctl -u sshd | grep 'Accepted publickey'
Oct 12 01:02:04 <hostname> sshd[54321]: Accepted publickey for <username> from <ip> port 12345 ssh2: ECDSA SHA256:ABCDEFGabcdefgABCDEFGabcdefgABCDEFGabcdefg
Oct 12 01:07:16 <hostname> sshd[54322]: Accepted publickey for <username> from <ip> port 12346 ssh2: RSA SHA256:abcdefgABCDEFGabcdefgABCDEFGabcdefgABCDEFG
Oct 12 07:24:13 <hostname> sshd[54323]: Accepted publickey for <username> from <ip> port 12347 ssh2: RSA SHA256:DEFGabcdefgABCDEFGabcdefgABCDEFGabcdefgABC
sudo -i -u username sh -c 'ssh-keygen -l -f ~/.ssh/authorized_keys'
2048 SHA256:abcdefgABCDEFGabcdefgABCDEFGabcdefgABCDEFG user1@example.com (RSA)
521 SHA256:ABCDEFGabcdefgABCDEFGabcdefgABCDEFGabcdefg user2@example.com (ECDSA)
4096 SHA256:DEFGabcdefgABCDEFGabcdefgABCDEFGabcdefgABC user3@example.com (RSA)
SSH Passwordless Login With Keychain
Install Keychain
dnf install keychain -y
# apt-get install keychain -y
# pkg install keychain -y
Generate a new ssh key if not exist
ssh-keygen -t ecdsa-sha2-nistp256 -C $USERNAME -f ~/.ssh/$USERNAME
Assign the pass phrase when prompted.
How to use Keychain
Update your $HOME/.bash_profile file or simular initialization file for zsh, fish, etc.
vi $HOME/.bash_profile
Append the following code:
alias sshkey_secured="keychain $USERNAME --nogui --quiet --timeout 60 ; source ~/.keychain/$HOSTNAME-sh"
source ~/.keychain/$HOSTNAME-sh
Run once in the same terminal to update environment:
…install selfhosted internal mailinator
Setup domain
- Log in https://my.freenom.com/
- buy yourdomain.here for $0/year
- set glue records:
KLEY.yourdomain.here - xxx.yyy.zzz.abc YELK.yourdomain.here - xxx.yyy.zzz.abc - Use custom nameservers:
KLEY.yourdomain.here YELK.yourdomain.here
Setup DNS service
sudo -i
dnf install bind bind-utils
cat > /etc/named.conf << TOLIK
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { none; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
recursion no;
dnssec-enable no;
dnssec-validation no;
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
include "/etc/crypto-policies/back-ends/bind.config";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
zone "yourdomain.here" {
type master;
file "yourdomain.here.hosts";
allow-transfer {
127.0.0.1;
localnets;
};
};
TOLIK
cat > /var/named/yourdomain.here.hosts << TOLIK
\$ttl 38400
@ IN SOA yourdomain.here. root.yourdomain.here. (
1461722457
10800
3600
604800
38400 )
yourdomain.here. IN A xxx.yyy.zzz.abc
kley.yourdomain.here. IN A xxx.yyy.zzz.abc
yelk.yourdomain.here. IN A xxx.yyy.zzz.abc
yourdomain.here. IN MX 5 yourdomain.here.
@ IN NS kley.yourdomain.here.
@ IN NS yelk.yourdomain.here.
TOLIK
named-checkconf /etc/named.conf
named-checkzone yourdomain.here /var/named/yourdomain.here.hosts
# zone yourdomain.here/IN: loaded serial 1461722457
# OK
Setup MAIL service
mkdir /srv/inbucket
chown daemon:daemon /srv/inbucket
dnf install -y https://github.com/inbucket/inbucket/releases/download/v3.0.0-beta3/inbucket_3.0.0-beta3_linux_amd64.rpm
mkdir /etc/systemd/system/inbucket.service.d/
cat > /etc/systemd/system/inbucket.service.d/override.conf << TOLIK
[Service]
Environment=INBUCKET_SMTP_ADDR=0.0.0.0:25
Environment=INBUCKET_SMTP_DOMAIN=yourdomain.here
Environment=INBUCKET_SMTP_MAXRECIPIENTS=2000
Environment=INBUCKET_SMTP_DEFAULTACCEPT=false
Environment=INBUCKET_SMTP_ACCEPTDOMAINS=yourdomain.here
Environment=INBUCKET_POP3_DOMAIN=yourdomain.here
Environment=INBUCKET_POP3_ADDR=127.0.0.1:1100
Environment=INBUCKET_WEB_ADDR=0.0.0.0:80
Environment=INBUCKET_WEB_MAILBOXPROMPT=@yourdomain.here
Environment=INBUCKET_WEB_MONITORHISTORY=1000
Environment=INBUCKET_STORAGE_TYPE=file
Environment=INBUCKET_STORAGE_PARAMS=path:/srv/inbucket
Environment=INBUCKET_STORAGE_RETENTIONPERIOD="8760h"
Environment=INBUCKET_STORAGE_RETENTIONSLEEP="3600s"
Environment=INBUCKET_STORAGE_MAILBOXMSGCAP="0"
NonBlocking=true
NoNewPrivileges=yes
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
LimitNOFILE=500000
LimitNPROC=500000
TOLIK
systemctl start inbucket
systemctl status inbucket
systemctl enable inbucket
google-chrome: clean passwords
Run google-chrome with –password-store=basic (example)
dnf install sqliteman
cp ~/.config/google-chrome/Default/Web\ Data{,.bak}
sqliteman ~/.config/google-chrome/Default/Web\ Data