Ssh: Unterschied zwischen den Versionen

Aus Vosp.info
Wechseln zu:Navigation, Suche
(ssh Server)
(sshd)
Zeile 70: Zeile 70:
 
PermitRootLogin prohibit-password
 
PermitRootLogin prohibit-password
 
PermitRootLogin yes
 
PermitRootLogin yes
 +
ChallengeResponseAuthentication no
 +
UsePAM no
 
</source>
 
</source>
  
 
* https://www.thomas-krenn.com/de/wiki/SSH_Root_Login_unter_Debian_verbieten
 
* https://www.thomas-krenn.com/de/wiki/SSH_Root_Login_unter_Debian_verbieten
 +
* https://www.cyberciti.biz/faq/how-to-disable-ssh-password-login-on-linux/
  
 
=== sftp ===
 
=== sftp ===

Version vom 1. Juli 2021, 16:42 Uhr

Allgemein

Debug Ausgaben

ssh -v ....

Authentifizierung über Public-Keys

Keypaar erstellen

 ssh-keygen -t rsa -b 4096
 ssh-keygen -t rsa -b 8192

Key überprüfen

ssh-keygen -l -f ~/.ssh/id_rsa.pub

Öffentlichen Schlüssel auf den Server kopieren

ssh-copy-id -i ~/.ssh/id_rsa.pub user@server
ssh-copy-id '-p 345 -i ~/.ssh/id_rsa.pub user@server'      // falls port anders
# bzw so
ssh-copy-id -p 345 -i ~/.ssh/id_rsa.pub user@server

auf den Server einloggen

 ssh user@server

Veralteten SSH-Schlüssel aus der known_hosts entfernen Fehlerausgabe:

 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!
 It is also possible that a host key has just been changed.
 The fingerprint for the RSA key sent by the remote host is
 aa:bb:cc:dd:ee:ff:gg:bd:f7:92:79:1c:cc:3b:af:11.
 Please contact your system administrator.
 Add correct host key in /home/sn/.ssh/known_hosts to get rid of this message.
 Offending RSA key in /home/sn/.ssh/known_hosts:7
 RSA host key for [78.46.110.16]:262 has changed and you have requested strict checking.
 Host key verification failed.

Lösung

 sed -i '7d' ~/.ssh/known_hosts

SSH Agent

SSH Agent zum speichern von Passwörtern:

im Terminal (so muss nur 1 das Passwort vom Key eingegeben werden):

 ssh-add

könnte ZB in die ~/.bashrc eingetragen werden .. dann wird mensch bei na neuen konsole aufgefordert und wenn mensch möchte

ssh Server

sshd

PermitRootLogin prohibit-password
PermitRootLogin yes
ChallengeResponseAuthentication no
UsePAM no

sftp

Installation

apt-get install openssh-sftp-server

Konfiguration

Linux Benutzer
groupadd sftponly

mkdir /home/sftp
mkdir /home/sftp/user1
mkdir /home/sftp/user2

useradd -g sftponly -s /usr/sbin/nologin -d /home/sftp/user1 user1
useradd -g sftponly -s /usr/sbin/nologin -d /home/sftp/user2 user2

passwd user1
passwd user2

chown root:sftponly /home/sftp/
chmod 750 /home/sftp/
chown user1: /home/sftp/user1
chown user2: /home/sftp/user2
chmod 700 /home/sftp/*
Extra public_html für den apache
mkdir /home/sftp/user1/public_html/
mkdir /home/sftp/user2/public_html/ 
chown -R  www-data:sftponly /home/sftp/user1/public_html/
chown -R  www-data:sftponly /home/sftp/user2/public_html/
chmod 755 /home/sftp/user1/public_html/
chmod 755 /home/sftp/user2/public_html/
chmod o+x /home/sftp/

sshd

am besten am Ende einfügen, auf jeden fall schauen das nachfolgende Einträge nicht zum Eintrag "Match Group sftponly" gezählt werden

  • /etc/ssh/sshd_config
Subsystem       sftp    internal-sftp

Match Group sftponly
	ChrootDirectory /home/sftp
	AllowTcpForwarding no
	ForceCommand internal-sftp -u 0027
	#PasswordAuthentication no
	#X11Forwarding no
Neustarten

Achtung: Immer in einer Extra Shell als root eingeloggt sein, falls Fehler drinn sind und mensch sich aussperrt!

service ssh restart && journalctl -xn

Quellen

ssh Clients and config

config

.ssh/config

Host  <your name, multiple names separated by spaces
Hostname <IP or FQDN>
User <user to logon with>
IdentityFile <the key you want to use>

Control multiple ssh hosts at once

mussh

Config

  • Pro Zeile ein <User>@<Host>
  • -H <file> liest die Config ein
  • -h behandelt den Parameter als einen Host
  • -c <command>
  • Das Ergebnis wird in der mussh aufrufenden Shell ausgegeben.

Anwendungsbeispiele

mussh -H <file with hosts> -c <command>

pssh

Config

  • Pro Zeile ein <User>@<Host>
  • -h <file> liest die Config ein
  • -i Das Ergebnis wird in der paralell-ssh aufrufenden Shell ausgegeben.
    • Ohne -i wird nur "Erfolg" oder "Misserfolg" angezeigt.
  • pssh bietet
    • parallel-nuke -- killing processes in parallel on a number of hosts
    • parallel-rsync -- copying files in parallel to a number of hosts
    • parallel-scp -- copying files in parallel to a number of hosts
    • parallel-slurp -- copying files in parallel from a number of hosts
    • parallel-ssh -- executing ssh in parallel on a number of hosts

Anwendungsbeispiele

Führt ein Command auf allen Hosts aus dem config-file aus und gibt den output auf der paralell-ssh aufrufenden Shell aus.

paralell-ssh -h <file with hosts> -i <command>

Führt ein Command auf allen Hosts aus dem config-file aus und zeigt nur nur "Erfolg" oder "Misserfolg" an.

paralell-ssh -h <file with hosts> <command>

Kopiert eine Datei auf alle Hosts aus dem config-file

paralell-scp -h <file with hosts> <file> <full remote path>

Quellen