Skip to content

Instantly share code, notes, and snippets.

@jirib
Last active March 12, 2021 16:03
Show Gist options
  • Save jirib/7a37a1ccfcbd3a4dbe802997214ec4d3 to your computer and use it in GitHub Desktop.
Save jirib/7a37a1ccfcbd3a4dbe802997214ec4d3 to your computer and use it in GitHub Desktop.
$ id; sftp -b - -s '/usr/bin/sudo /usr/libexec/sftp-server' localhost << EOL
> pwd
> cd /root
> ls -al
> quit
> EOL
uid=1000(jiri) gid=1000(jiri) groups=1000(jiri),4(wheel),12(audio),13(video),20(scanner),21(network),987(docker),990(libvirt),995(bluetooth)
sftp> pwd
Remote working directory: /home/jiri
sftp> cd /root
sftp> ls -al
drwxr-x--- 6 root root 4096 Mar 11 15:17 .
drwxr-xr-x 18 root root 4096 Mar 12 10:56 ..
-rw------- 1 root root 12727 Mar 9 01:17 .bash_history
drwxr-xr-x 5 root root 4096 Feb 19 17:58 .cache
drwx------ 3 root root 4096 Feb 15 15:45 .config
drwx------ 3 root root 4096 Feb 25 23:10 .emacs.d
-rw------- 1 root root 436 Mar 11 15:17 .lesshst
drwx------ 2 root root 4096 Feb 19 23:41 .trousers
-rw-r--r-- 1 root root 274 Feb 26 20:14 .wget-hsts
sftp> quit
```
$ egrep -v '^(#|$)' /etc/ssh/sshd_config
LogLevel DEBUG3
AuthorizedKeysFile .ssh/authorized_keys
ChallengeResponseAuthentication no
UsePAM yes
PrintMotd no
Subsystem sftp /usr/libexec/sftp-server
Match User jiri
X11Forwarding no
AllowTcpForwarding no
PermitTTY no
ForceCommand /usr/bin/sudo /usr/libexec/sftp-server
```
```
$ id; sftp -b - localhost << EOL
pwd
cd /root
pwd
ls -la
EOL
uid=1000(jiri) gid=1000(jiri) groups=1000(jiri),4(wheel),12(audio),13(video),20(scanner),21(network),987(docker),990(libvirt),995(bluetooth)
sftp> pwd
Remote working directory: /home/jiri
sftp> cd /root
sftp> pwd
Remote working directory: /root
sftp> ls -la
drwxr-x--- 6 root root 4096 Mar 12 16:51 .
drwxr-xr-x 18 root root 4096 Mar 12 10:56 ..
-rw------- 1 root root 12727 Mar 9 01:17 .bash_history
drwxr-xr-x 5 root root 4096 Feb 19 17:58 .cache
drwx------ 3 root root 4096 Feb 15 15:45 .config
drwx------ 3 root root 4096 Feb 25 23:10 .emacs.d
-rw------- 1 root root 478 Mar 12 16:51 .lesshst
drwx------ 2 root root 4096 Feb 19 23:41 .trousers
-rw-r--r-- 1 root root 274 Feb 26 20:14 .wget-hsts
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment