Ssh: Unterschied zwischen den Versionen

Aus robopagex.com
Zur Navigation springen Zur Suche springen
Zeile 113: Zeile 113:
 
==== ''' ssh commands ''' ====
 
==== ''' ssh commands ''' ====
 
  $ssh -luser 192.xx.xxx.xx
 
  $ssh -luser 192.xx.xxx.xx
  $ssh user@192.168.179.113 'ls -la /home/user'
+
  $ssh user@192.168.188.2 'ls -la /home/user'
  
 
==== ''' ssh execute command ''' ====
 
==== ''' ssh execute command ''' ====

Version vom 21. Juli 2021, 22:52 Uhr

Links

explainshell
Screen
nohup
linuxcommand ssh1
open ip

SSH, FUSE, SSHFS

SSH STATUS

$ systemctl status ssh 
$ whoami
$ who
$ w
$ ps
$ ps aux
$ ps aux | grep ssh 
$ ps aux | grep sshd 
$ lsof -i -n | egrep 'ssh' 
$ lsof -i -n | egrep 'sshd' 
$ ss 
$ ss -l
$ ss | grep tcp
$ ss | grep -i ssh
$ ss -u -a
$ last -a | grep -i still
apk*error
$ service ssh status 
$ netstat -tanup | grep ssh 
$ netstat -tnpa | grep 'ESTABLISHED.*sshd
$ firewall-cmd --list-all-zones 

Create SSH Key

$ ssh-keygen -t ed25519 -b 4096

Copy SSH Key

$ ssh-copy-id  -i KEY user@IP
$ ssh-copy-id  -i ~/.ssh/KEY user@IP

Login with SSH Key

$ ssh -i ~/.ssh/KEY user@IP -p 5001

SSHFS FUSE

$ sshfs user@host:/dir /dir -o IdentityFile=~/.ssh/KEY
$ sshfs user@host:/dir /dir -o IdentityFile=~/.ssh/KEY -o idmap=user -o uid=$(id -u) -o gid=$(id -g)
$ sshfs user@host:/dir /dir -C -p 5001
$ sshfs user@host:/dir /dir -o IdentityFile=~/.ssh/KEY -o idmap=user -o uid=$(id -u) -o gid=$(id -g) -o nonempty -p 5001 
$ fusermount -u /dir 

Reverse SSH Tunnel

Check for:
1. ServerAliveInterval(sshd_config)
2. autossh
ssh -R 5001:localhost:22 -fN IP

AutoSSH SSH Tunnel

$ autossh -NT -o "ExitOnForwardFailure=yes" -R 5001:localhost:6001 -l USER IP -p 7001 -i /home/USER/.ssh/KEY
$ autossh -N -f -i /home/<user>/.ssh/id_rsa -R 22222:localhost:22 <user>@<remote_host>
-N: tell ssh to not execute any command, since we only use it for tunneling.
-f: tell autossh to fall into background on start.
-i: tell ssh to use the proper identity.
-R 22222:localhost:22: 
reverse tunnel remote host's 22222 port to localhost's 22 port. 
So that we can use ssh -p 22222 localhost on remote host to ssh into local machine.
nano /etc/systemd/system/sshtunnel.service 
sshtunnel.service
[Unit]
Description=AutoSSH tunnel service
#After=network.target
After=network-online.target ssh.service
[Service]
User=USER
Environment="AUTOSSH_GATETIME=0"
RestartSec=30
Restart=always
ExecStart=/usr/bin/autossh -NT -o "ExitOnForwardFailure=yes" -R 5001:localhost:6000 -l USER IP -p 6001 -i /home/USER/.ssh/KEY
ExecStop=pkill -s KILL autossh
TimeoutStopSec=10
[Install]
WantedBy=multi-user.target
systemctl status sshtunnel.service
systemctl daemon-reload
systemctl restart sshtunnel.service

When using ssh multiplexing, killing the ssh process is often undesirable 
(it kills all open connections with that host), 
and you cannot easily access the escape because "escape not available to multiplexed sessions". 
The right way is then to run the analogue of the forwarding command that you want to cancel, 
but adding -O cancel. For instance:
ssh -O cancel -L 5002:192.168.0.10:5002 192.168.178.100
This will disable this port forwarding without terminating the session. Again, this will only   
work if ssh multiplexing is in use for the connection to 192.168.178.100


ssh commands

$ssh -luser 192.xx.xxx.xx
$ssh user@192.168.188.2 'ls -la /home/user'

ssh execute command

ssh execute script

secure file transfer

SCP
$ pscp
$ scp
$ scp test user@192.168.188.2:/home/user/scp_test 
sftp
psftp