xpressai
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # The Comprehensive SSH Guide Hey guys, it's Laziem and Fahreza (mostly Laziem). This is guide that we wrote, especially since a lot of it is new to Fahreza and hopefully can be useful to you too. We've often heard or perhaps even used SSH in our tasks, ie access Konsole via SSH. But you might also want to setup your own SSH, say from your windows bash terminal to WSL or maybe setting up a Hadoop server - this guide is for you. If you would like to reproduce this tutorial, you can try the setup on a Virtual Box. The Windows version is [here](https://www.extremetech.com/computing/198427-how-to-install-windows-10-in-a-virtual-machine). Ensure that you have both openssh-client and openssh-server installed. ## Soft Introduction to SSH ~insert simple explaination on SSH~ Now, there's multiple ways of SSHing. Once you have openssh-server and openssh-client on both devices, you can simply SSH to each other by using ``` $ ssh username@ip-address ``` You will then be prompted to enter the username's password. This however isn't secure and hackers can easily break in by supplying common commands. The best way is to use public and private keys. ~insert diagrams about public and private keys~ To generate your keys, use: ``` $ ssh-keygen -t rsa ``` Where -t is the type of encryption, here we choose rsa. You then will be prompted to choose where you would like to save your keys (default: /home/username/.ssh/id_rsa) and whether you would like to set a passphrase. I'd usually keep the default and leave it without a passphrase. Two files will be generated, your private key "id_rsa" and your public key "id_rsa.pub". This public key is what you send over to the server so they can authenticate your access. To send it over, use: ``` ssh-copy-id root@ip-address ``` ## Linux / Mac / Windows ### Basic Preferably use bash for windows user. ``` ssh username@IP_ADDR -p PORT ``` - Edit `~/.ssh/config` to simplify it. - In windows config file is in `c:\Program Files\Git\etc\ssh\ssh_config` if you are using [Git for windows](https://git-scm.com/download/win). - The default should be in `c:\Users\myname\.ssh\config` For example this config: ``` Host trainingMachine HostName ip_addr IdentityFile ~/path/to/key IdentitiesOnly yes User muhdlaziem Port 22 ``` - `IdentityFile` and `IdentitiesOnly` are optional in most cases depending on the machine's config. - If needed make sure private key and public key are kept in same place. - Generate keys using this command `ssh-keygen -t rsa -b 2048`. `-b` is depending on machine's config. --- After editing config file. We can easily ssh using this command: ``` ssh trainingMachine ``` ### Install OpenSSH client and server in Windows using Powershell To Install: [microsoft docs](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse) ### Powershell Host Key Generation <WIP> So a server admin asked you to pass your sshkey and you have no idea how to do it. Here's the steps you need to do: Make sure you've installed openSSH. Then you might want to set the openSSH server to be started automatically. In powershell, run: ``` # Set the sshd service to be started automatically Get-Service -Name sshd | Set-Service -StartupType Automatic # Now start the sshd service Start-Service sshd ``` Generate your SSH by ``` ssh-keygen ``` ``` ssh-add -l ``` Source [microsoft docs](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement) ### Port Forwarding From local to remote. `ssh host -L local_port:ip_addr/host:remote_port` ``` ssh trainingMachine -L 8080:localhost:8080 ``` - This is useful when we need to access / monitor some resources from the remote. Example: Kubernetes Dashboard (10443) or Hadoop Dashboard (8088) From remote to local. `ssh host -R remote_port:localhost:local_port` ``` ssh trainingMachine -R 8088:localhost:8080 ``` - This is useful when we need to give access some of local resources to the remote. - Take note that not all ports can be used. For hadoop, you can try 8088, 4040. - For more complex operations such as connecting to a Jupyterlab instance created in a Konsole environment, you might want to consider using VSCode. It can automatically connect the remote env to your local browser. ## Working remotely using VS code 1. Download **Remote-SSH** extension ![Remote-SSH](https://i.imgur.com/WwZdXXz.png) 2. Open Remote Explorer ![Remote-Explorer](https://i.imgur.com/MLavA3s.png) 3. Add New SSH Targets ![](https://i.imgur.com/wn4csF9.png) 4. Enter your command: ![command](https://i.imgur.com/1IGzXFt.png) 5. Select your config file ![config](https://i.imgur.com/78tfk8K.png) 6. New SSH Target will appear here. Click the folder icon. A prompt will likely to appear to enter a password ![prompt](https://i.imgur.com/PL4GVsp.png) 7. This means your ssh is working. You can now open folder as you like. ![works](https://i.imgur.com/pjEqYSQ.png) 8. You can port forwarding easily in vscode. Click the antenna icon ![port-forwarding](https://i.imgur.com/z2JO8cC.png) 9. Click `Forward a Port button` and Enter your port. ![enter-port](https://i.imgur.com/fgwt57W.png) --- ## Passwordless SSH (Linux & MacOS) This is where we use keys instead of password. 1. First, we need to generate our keys. Run `ssh-keygen -t rsa -b 2048`. Here, you will need to enter keys path (by default it will be stored in `~/.ssh/id_rsa`) and passphrase. 2. Assume, we use `trainingMachine` as our remote host. Run `ssh trainingMachine mkdir -p .ssh`. 3. Run `cat ~/.ssh/id_rsa.pub | ssh trainingMachine 'cat >> .ssh/authorized_keys'`. 4. We probably need to ensure permission is correct by running `ssh trainingMachine "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"`. 5. Finally, we can SSH without entering password: `ssh trainingMachine`. 6. If we import keys from somewhere else, we might need to run `ssh-add -K ~/.ssh/keyname` to add our key to local Keychain. For some reasons in different OS like macOS. They did not add our Keys by default in Keychain. By running the same command, mostly, it will solve the problem. - In MacOS, I added config below in `~/.ssh/config` after adding keys to Keychain to make sure the keys will persist. ``` Host * UseKeychain yes AddKeysToAgent yes IdentityFile ~/.ssh/machine1 IdentityFile ~/.ssh/machine2 IdentityFile ~/.ssh/machine3 ``` Source: [Click this link](https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully