> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/file-transfers/transfers-with-ssh.md).

# Transfers with SSH

## Download file(s) with SCP

Retrieve files from a SSH-server running on a non-standard port (`-P <port_num>`)

```bash
kali@kali:~$ scp -P 2222 offsec@192.168.50.151:/home/offsec/.bash_history offsecHistory.txt
offsec@192.168.50.151's password: 
.bash_history                                                100%   4865    31.1KB/s   00:00
```

## Upload file(s) with SCP

To upload files to a taget machine

```bash
┌──(kali㉿kali)-[/mnt/…/Hack_the_Box/HTB_Machines/Easy_Machines/Titanic]
└─$ scp linpeas.sh developer@$TARGET_IP:/home/developer/linpeas.sh
developer@10.10.11.55's password: 
linpeas.sh                                                 100%  932KB   1.6MB/s   00:00
```

## Start an SSH server

If an SSH-server is already installed on the machine you can start it with

```bash
cat /etc/ssh/sshd_config            # check the config
sudo systemctl start ssh
```

When you are done use

```bash
sudo systemctl stop ssh
```

to stop the server.

## Usage information

<details>

<summary>scp -h</summary>

```bash
┌──(kali㉿kali)-[~]
└─$ scp -h    
scp: unknown option -- h
usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]
           [-i identity_file] [-J destination] [-l limit] [-o ssh_option]
           [-P port] [-S program] [-X sftp_option] source ... target

```

</details>

## References

scp - Linux manual page: <https://man7.org/linux/man-pages/man1/scp.1.html>

Secure Shell - Wikipedia: <https://en.wikipedia.org/wiki/Secure_Shell>
