Pour générer le fingerprint (md5 ou sha256) de votre clé ssh publique
Vous pouvez faire :
ssh-keygen -lf ~/.ssh/id_ed25519.pub
ou
ssh-keygen -l -E md5 -f ~/.ssh/id_ed25519.pub
C’est pratique pour faire la correspondance entre clé publique en local sur son poste et le fingerprint dans l’interface de Github ((https://github.com/settings/keys)
-
https://links.infomee.fr/?DnYicwj'avais perdu cet article, il est là!
-
https://code.fb.com/security/scalable-and-secure-access-with-ssh/not bad! better than unprotected socket access ;)
-
https://medium.com/lucjuggery/docker-tips-access-the-docker-daemon-via-ssh-97cd6b44a53?mkt_tok=eyJpIjoiTmpZNE5HWXdOVFJtWkRWbCIsInQiOiI1b0Zsb1RkNk4rXC9qSWtyajFCN3RsSERRQytkSk0wRzZkQ3dRU3g0eXM0YUV3R3RWM1dpb3dqNXpYVjc4MUlNMmpcL1ZIeGdLbk1yQjZYZjNIbjczOTBLOUY4YlBsSUVQRVZwMUg5bGZnNlRHOXpTaFdhdkIydnhmTFd1V0JyRE50In0%3DSolution 1 (recommended)
Apple updated its Technical Notes to indicate that since 10.12.2, macOS includes version 7.3p1 of OpenSSH and its new behaviors.
In ~/.ssh create config file with the following content:
Host * (asterisk for all hosts or add specific host)
AddKeysToAgent yes
UseKeychain yes
IdentityFile <key> (e.g. ~/.ssh/userKey)
-
https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychainEncore un exemple d'utilisation de env= dans le authorized keys
via skunnyk
-
http://damiengustave.fr/ssh-blamer/variables=~/.ssh/variables
sshadd() {
source "$variables" > /dev/null
ssh-add -l > /dev/null 2>&1
case "$?" in
1)
ssh-add /root/.ssh/key > /dev/null 2>&1
;;
2)
rm "$variables"
sshagent
;;
esac
}
sshagent() {
if [ -f "$variables" ] ; then
sshadd
else
ssh-agent -s > $variables
sshadd
fi
}
sshagent
source /root/agentmanagement.sh
-
https://links.infomee.fr/?F4oSMA.ssh/authorized_keys
environment="GIT_AUTHOR_NAME=Arnaud M",environment="GIT_AUTHOR_EMAIL=arnaud@foo.bar",environment="GIT_COMMITTER_NAME=Arnaud M",environment="GIT_COMMITTER_EMAIL=arnaud@foo.bar" ssh-rsa .....
Peut être pratique quand plusieurs personnes commit depuis le même serveur (pour avoir un historique git avec les noms..)
-
http://cweiske.de/tagebuch/carry-git-settings.htmTo manage multiple identities
-
https://github.com/ccontavalli/ssh-identIt took me some time to figure this one out, as everybody is using rsync and ssh-keys without passphrases, but I insist that an ssh-key should have a passphrase.
In my first attemts I got this error messages mailed to me by crontab:
Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive).
Here are the steps to automate a backup initiated from crontab using rsync, SSH and ssh-keys with a passphrase:
Make a set of SSH keys.
Setup SSH to use the agent automatically.
Login once as the user who's cron will run the backup script. You will be asked for a passphrase. When the machine reboots, you will need to login once more, to enter the passphrase again.
Make a backup script that includes some SSH variables.
This script could be as simple as this:
. /home/username/.ssh/variables
rsync -avz --delete /data/ example.com:data
N.B. This variables file only contains these lines:
SSH_AUTH_SOCK=/tmp/ssh-DmFcb18036/agent.18036; export SSH_AUTH_SOCK;
SSH_AGENT_PID=18037; export SSH_AGENT_PID;
echo Agent pid 18037;
Put that script in crontab.
That should do it for you, as it works like a charm for me!
-
https://meinit.nl/using-rsync-from-cron-with-ssh-keys-that-have-a-passphrasevariables=~/.ssh/variables
sshadd() {
source "$variables" > /dev/null
ssh-add -l > /dev/null 2>&1
case "$?" in
1)
ssh-add > /dev/null 2>&1
;;
2)
rm "$variables"
sshagent
;;
esac
}
sshagent() {
if [ -f "$variables" ] ; then
sshadd
else
ssh-agent -s > $variables
sshadd
fi
}
sshagent
-
https://meinit.nl/enter-your-ssh-passphrase-once-use-it-many-times-even-from-crontab-R [bind_address:]port:host:hostport
ssh -R *:8080:localhost:80 -N root@website.com
or
ssh -R 0.0.0.0:8080:localhost:80 -N root@website.com
or
ssh -R [::]:8080:localhost:80 -N root@website.com
Note that if you use OpenSSH sshd server, the server's GatewayPorts option needs to be enabled (set to yes or clientspecified) for this to work (check file /etc/ssh/sshd_config on the server). Otherwise (default value for this option is no), the server will always force port bound on the loopback interface only.
-
http://superuser.com/questions/588591/how-to-make-ssh-tunnel-open-to-publicerrs = []
def test_server(errs, server)
lambda do |options|
begin
server =~ /(.+)@(.+)/
server_name, user = $2, $1
puts server_name
s = Net::SSH.start(server_name, user)
s.close
s = server
rescue Errno::EHOSTUNREACH, SocketError
puts "echec connexion #{server} : #{$!}"
errs << server
s = nil
end
return s
end
end
Net::SSH::Multi.start(:on_error => :warn) do |session|
session.use &test_server(errs, 'root@srv-04')
session.use &test_server(errs, 'root@srv-07')
session.use &test_server(errs, 'root@srv-08')
session.use &test_server(errs, 'root@fail-08.local')
session.exec( "hostname" )
session.loop
end
unless errs.empty?
puts "The command failed on #{errs.size} hosts"
end
-
http://marc.info/?l=ruby-talk&m=122278906522776&w=2Dans les logs d'accès ssh (/var/log/auth.log), si vous avez passé le loglevel de SSH à VERBOSE, vous pouvez voir pour chaque accès la clé qui a été utilisé.
Le format est différent de celui dans authorized_keys pour des raisons de lisibilité j'imagine.. Pour faire la conversion depuis authorized_keys vers ce format :
echo key | base64 | md5
ou
ssh-keygen -lf key.pub
-
http://superuser.com/questions/421997/what-is-a-ssh-key-fingerprint-and-how-is-it-generatedTrouver tous les pid des sessions ssh en cours :
ss -tnp|grep ':22'
ss -tp|grep ':22'|grep -Eo ',[0-9]+,'|grep -Eo '[0-9]+'
Trouver depuis quand ces process sont démarrés :
26205 329840
1419103787
Sat Dec 20 20:31:42 CET 2014
One liner :
start time
for pid in $(ss -tp|grep ':22'|grep -Eo ',[0-9]+,'|grep -Eo '[0-9]+'); do date -d@$(echo "$(date +%s) - $(ps -o etimes -p $pid --no-headers)"|bc); done
pid + start time
Si le log level de ssh est en VERBOSE, on peut chercher dans auth.log le fingerprint de la clé publique correspondant à la date à laquelle une session ssh a démarré :
-
https://links.infomee.fr/?9HRSiQJe préfère cette solution, à savoir passer sshd en VERBOSE.
L'autre solution consiste à utiliser environment dans le fichier authorized_keys puis à écrire dans un fichier (à l'aide de .bashrc par exemple). Mais l'utilisateur peut modifier ce fichier..
ssh-keygen -lf /path/to/public_key_file
-
http://serverfault.com/questions/291763/is-it-possible-to-get-openssh-to-log-the-public-key-that-was-used-in-authenticatwow could be useful
via skunnyk
-
https://github.com/Russell91/sshrcpetit rappel
cheatsheet bien faite
-
http://pentestmonkey.net/cheat-sheet/ssh-cheat-sheetBon ce code n'a pas marché chez moi... mais il faut bien garder en tête qu'une clé chargée avec un agent va résider en mémoire de manière non chiffrée ;)
Et de la même manière, elle va résider en mémoire sur un hôte distant si on se connecte en 'ssh -A'. Donc potentiellement, quelqu'un qui a un accès root sur cette machine distante peut récupérer les clés privés des gens qui s'y connectent (en -A)
github link via skunnyk
-
https://github.com/NetSPI/sshkey-grabQuelques pistes pour monitorer le TCPforwarding
-
http://blog.rootshell.be/2009/03/01/keep-an-eye-on-ssh-forwarding/This morning a discussion with a friend about various shells lead me to think it would be nice if my bash shell could tab complete hostnames from .ssh/known_hosts when I type ‘ssh <tab>’. I soon found this blog post which nicely documents how to do it. I made a directory in $HOME called .bash.completion and then added this to my .profile, which loops round any files in there, sourcing them individually:
if [ -d ${HOME}/.bash.completion ]; then
for file in ${HOME}/.bash.completion/* ; do
source $file
done
fi
All sorted. However, it wasn’t long before I discovered that ‘ssh user@<tab>’ doesnt work, I tend to use this quite a lot so wanted to see if I could fix up the bash function to support that use case. Bit of hacking around and I’ve got it working, the replacement ssh-completion file is shown below:
__ssh_known_hosts() {
if [[ -f ~/.ssh/known_hosts ]]; then
cut -d " " -f1 ~/.ssh/known_hosts | cut -d "," -f1
fi
}
_ssh() {
local cur known_hosts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
known_hosts="$(__ssh_known_hosts)"
if [[ ! ${cur} == - ]] ; then
if [[ ${cur} == @ ]] ; then
COMPREPLY=( $(compgen -W "${known_hosts}" -P ${cur/@/}@ -- ${cur/*@/}) )
else
COMPREPLY=( $(compgen -W "${known_hosts}" -- ${cur}) )
fi
fi
return 0
}
complete -o bashdefault -o default -o nospace -F _ssh ssh 2>/dev/null \
|| complete -o default -o nospace -F _ssh ssh
-
http://usefulthings.org.uk/2013/04/bash-ssh-known_hosts-tab-completion/Une astuce utile pour faire un audit des connexions par clé sur un compte (quand on a plusieurs personnes avec des clés différentes qui accèdent au meme user)
Implémentation rapide :
#On convertit le authorized_keys pour ajouter la variable d'env
cp ~/.ssh/authorized_keyz ~/.ssh/authorized_keyz.ORIGINAL
IFS=$'\n'
for line in $(cat .ssh/authorized_keys)
do
comment=$(echo $line|cut -d' ' -f3)
echo "environment=\"SSH_USER=$comment\" $line" >> ~/.ssh/authorized_keyz.COMMENT
done
cp ~/.ssh/authorized_keyz.COMMENT ~/.ssh/authorized_keyz
Puis dans le bashrc de l'user, ajouter ça :
if [ "$SSHUSER" != "" ]; then
now=$(date +%Y-%m-%d%H-%M-%S)
echo $now : User $SSH_USER logged in >> ~/ssh-audit.log
fi
-
http://www.screenage.de/blog/2012/02/10/how-to-log-history-and-logins-from-multiple-ssh-keys-under-one-user-account-with-puppet/Ahah a tester
-
http://Twitter / climagic: Confuse people SSHing to your host with a redirect back to theirs - @jeekajoo ~/µblog https://fralef.me/links/?eGhuHQalternatives à authorized_keys
via Skunnyk
-
http://connect.ed-diamond.com/GNU-Linux-Magazine/GLMF-161/AuthorizedKeysCommand-quand-OpenSSH-devient-CloudSSH.-Nan-j-deconneCool stuff :
ssh user@server 'bash -s' < local_script.sh > local_script.log 2>&1
-
https://links.infomee.fr/?ORnmyQnot bad
$ sudo /usr/sbin/sshd -t
$ echo $?
-
http://www.cyberciti.biz/tips/checking-openssh-sshd-configuration-syntax-errors.htmlIn Firefox, the solution is easy. Simply type about:config in the address bar and set network.proxy.socks_remote_dns to true. This will have the remote end (i.e., the machine you are SSH’ing to) handle the DNS lookups.
-
http://fooninja.net/2010/09/06/how-to-tunnel-everything-through-ssh/Un serveur, mais surtout un client pour faire du port knocking
-
http://www.prometheus-group.com/labs/unbounded/46-web-security/135-bash-pk.htmlPour utiliser machinerebond pour accéder aux *.vm automatiquement :
$ cat .ssh/config
Host=machinerebond
Hostname=machinerebond.fqdn.com
User=root
Host=*.distant
User=root
ProxyCommand=ssh -W %h:22 machinerebond
Alternative :
D'abord se co sur la machine rebond avec un -A pour ramener sa key dans l'agent distant
Ensuite on peut se co sur les autres machines, mais plus long.
Autres directives possibles :
ServerAliveInterval 30
ServerAliveCountMax 120
Port 22000
User fooey
IdentityFile ~/.ssh/github.key
LocalForward 9906 127.0.0.1:3306
more : http://www.openbsd.org/cgi-bin/man.cgi?query=ssh_config&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html
-
https://links.infomee.fr/?0hyAJQGeneration de clé ssh, keygen ssh
-
http://www.linux-france.org/prj/edu/archinet/systeme/ch13s03.html