-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
297 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# OpenSSH Quick Start | ||
|
||
## The Authentication | ||
|
||
A host machine that running a SSH server can be called as **Remote** which should store *public keys* for client hosts. | ||
A host machine(client) attempting to connect with Remote should know a *private key* and *passphrase*. | ||
This is how the authentication happen: | ||
|
||
1. Client sends request to Remote. | ||
2. If the Client had never connect to the Remote, warning prompts to confirm connection implying it may be dangerous. | ||
3. If any public key on Remote matches the client, Remote requests the client for authenticator which should be calculated by *passphrase* and *private key* | ||
4. User enter the *passphrase* to decrypt the private key, SSH auto-calculates the authenticator, then send it to the Remote. | ||
|
||
## Client Side | ||
|
||
- Generate public key for connecting **one or more** remotes by `ssh-keygen` | ||
```sh | ||
ssh-keygen -t rsa | ||
``` | ||
- Register new public key to remote by `ssh-copy-id`(may require login on remote) | ||
```sh | ||
# add public key under `~/.ssh/` to `~/.ssh/authorized_keys` on <remote> | ||
ssh-copy-id -i <pub_key_file> [<username>@]<remote> | ||
``` | ||
- Managing authenticated state and **agent forwarding** by `ssh-agent` | ||
```sh | ||
ssh-agent $SHELL | ||
``` | ||
- Add private key to `ssh-agent` to memorize the state of the key by `ssh-add` | ||
```sh | ||
ssh-add ~/.ssh/id_ed25519 | ||
ssh-add -l # list all private keys memorized by ssh-agent | ||
ssh-add -d id_ed25519 # inform ssh-agent to forget this key | ||
ssh-add -D # forget all keys | ||
``` | ||
- Managing once connected remote in `~/.ssh/known_hosts` | ||
- File transfer by `scp` | ||
- Modify *passphrase* by `ssh-keygen` if you forgot | ||
```sh | ||
ssh-keygen -p | ||
``` | ||
|
||
## Server Side | ||
|
||
- Start SSH server by `sshd` | ||
- Manage SSH server config by `/etc/ssh/sshd_config` | ||
- Manage public key for multiple clients in `~/.ssh/authorized_keys` | ||
> [!NOTE] | ||
> Besides `ssh-copy-id`, you can directly edit `~/.ssh/authorized_keys` to add new public key for a client. | ||
|
||
## Create Key Pair | ||
|
||
```sh | ||
ssh-keygen [-t <type>] [-f <path>] [-N <passphrase>] [-C <comment>] | ||
``` | ||
|
||
- `-t`: specify key type, `ed25519` by default. | ||
- `-f`: output fullname of the key, public key will have extra extension `.pub`. `ssh-keygen` will prompt for it if not specified anyway. | ||
- `-N`: specify passphrase, will ask anyway if unspecified. This may expose your passphrase to command history. | ||
- `-C`: comment for identifying the key. | ||
|
||
> [!NOTE] | ||
> see `man ssh-keygen` | ||
## Re-encrypt Key | ||
|
||
You might want to encrypt the keys with different type and passphrase, as well as a new name. | ||
|
||
```sh | ||
ssh-keygen -p [-t <type>] [-f <path>] [-P <old_passphrase>] [-N <new_passphrase>] | ||
``` | ||
|
||
Similar to creating a key pair, you don't have to fill all options, leave them empty and let the cli prompt for you. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Setup nix-on-droid | ||
|
||
## Prerequisites | ||
|
||
- Root privilege on you android phone(it's not stable in devices without root) | ||
- nix-on-droid installed. | ||
- Optional: `adb`, `pwsh` | ||
You can use `adb` to type inputs from your computer connected with your android device. | ||
The following powershell function solves the escape problem of `adb shell input text`, so you don't have to escape manually. | ||
```ps1 | ||
# Use -Enter to press enter after command input | ||
function adbin([string]$Str, [switch]$Enter) { | ||
$special = @( ' ', '\|', '\$', '&', '\(', '\)', '~','\*', "\'",'"','<','>') | ||
foreach ($char in $special) { | ||
$Str = $Str -replace $char, ($char.Length -gt 1 ? $char : "\$char") | ||
} | ||
adb shell input text $Str | ||
if ($Enter) { | ||
adb shell input keyevent KEYCODE_ENTER | ||
} | ||
} | ||
``` | ||
> [!NOTE] | ||
> You can wrap the same as bash function by `awk` or other text manipulation tools. | ||
## Init | ||
- nix-on-droid may ask for url for certain file, if the url is not accessible on your phone, download it and transfer to your phone. And replace the default url as `file:///sdcard/...` | ||
- type `yes` when nix prompt for downloads for first init. | ||
- add and update channels: | ||
```sh | ||
nix-channel --add /~https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager && channel | ||
``` | ||
> [!TIP] | ||
> If you use the wrapper function mentioned above, would be like this: | ||
>```ps1 | ||
>adbin -Enter 'nix-channel --add /~https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager' | ||
>``` | ||
## Connect to nix-on-droid | ||
- Install `openssh` | ||
```sh | ||
nix profile install nixpkgs#openssh | ||
``` | ||
|
||
- create a empty `ssh_config`, `sshd` requires at least one specified. We don't specify any option in it in this guide but it's needed afterward. | ||
|
||
```sh | ||
mkdir -p /etc/ssh/ && touch /etc/ssh/sshd_config | ||
``` | ||
|
||
- generate a host key for nix-on-droid, change the key type and passphrase as you like, they don't make too much difference. | ||
|
||
```sh | ||
ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key -N "" # key is generated in pwd | ||
``` | ||
|
||
- create `~/.ssh/authorized_keys` and paste your public key from your computer(`gc ~/.ssh/<name>.pub`) to this file. | ||
|
||
```sh | ||
mkdir -p ~/.ssh/ && touch ~/.ssh/authorized_keys && echo <pub> >> ~/.ssh/authorized_keys | ||
``` | ||
|
||
- start ssh daemon by `sshd` | ||
|
||
```sh | ||
sshd -p <port> -h <host_key> -d | ||
``` | ||
|
||
`-d` is essential to know whether your port is been taken or not. See details in `man sshd`. | ||
|
||
- now connect to nix-on-droid from your computer | ||
|
||
```ps1 | ||
ssh -l nix-on-droid -p <port> <ipaddr_of_phone> | ||
``` | ||
|
||
> [!NOTE] | ||
> `<ipaddr_of_phone>` can be inspected from your `Settings - About phone` | ||
## Final Step | ||
|
||
Finally you can type everything in your computer through SSH! So use nix as you like. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
docs/document/PowerShell/docs/File System/6. Inspect File System.md
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
docs/document/PowerShell/docs/File System/6.Inspect File System.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Inspect File System | ||
|
||
## List Items | ||
|
||
- Recursively | ||
|
||
```ps1 | ||
gci -rec | ||
``` | ||
|
||
- Include Hidden Items | ||
|
||
```ps1 | ||
gci -force | ||
``` | ||
|
||
## Size | ||
|
||
- Directory Size | ||
|
||
```ps1 | ||
gci -file -rec -force | measure { $_.Length / 1MB } -Sum | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
9 changes: 0 additions & 9 deletions
9
docs/document/PowerShell/docs/Object Manipulation/1.Overview.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Group | ||
|
||
- Group by property by `-Property` |
21 changes: 0 additions & 21 deletions
21
docs/document/PowerShell/docs/Object Manipulation/ETS Property.md
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.