Notes
  • Notes
  • JavaScript
    • URL processing
    • Numbers
  • Python
    • python random notes
    • Python Resources
  • Setup
    • Mac Setup
  • Command Line
    • Basics
    • Linux basics
    • Bash script
    • Create temp files
    • awk
    • sed
    • make
    • ssh
    • gzip
    • Command line tools
    • ffmpeg
    • at and crontab - scheduling commands
  • Web Developement
    • Chrome Dev Tools
    • HTML
    • Markdown
    • CSS
    • Rails
    • Hugo
    • REST APIs
  • Soft Skills
    • Listening Skills
    • Public Speaking
  • Containers
  • Career
    • Resume
    • Interview
    • Promotion
    • Keeping Track of Your Work
    • Decide What to Work On
  • Ergonomics
    • Work Env Setup
    • Pain Relieve
  • Digest / Writing Ideas
    • Books
      • Antifragile
      • Anti-Intellectualism in American Life 美国的反智传统
    • Economy / Society
    • How to spend your time
    • Life
    • Higher education
  • Misc
    • Regex
    • Don't Make Me Think
    • Microsoft Excel
    • AdTech 101
  • Resources
    • web
    • Vim
    • Tools
    • System Design
    • Design Pattern
    • Load Balancer
    • References
    • Hardware
    • Algorithm Resources
    • Command Line Resources
  • Git
    • Pro Git
  • Non-Tech
    • 化学科普 - 拿破仑的纽扣
    • 人生经验 - If I Knew Then
    • 哲学
      • Harvard - Justice
    • 宗教
      • Introduction to the New Testament History and Literature
      • 蔡志忠 - 漫画东方圣经
    • 人文
      • Open Yale Course - 心理学导论
  • Spark
  • VS Code
Powered by GitBook
On this page
  • config file: .ssh/config
  • SCP
  • SSH Tunnel

Was this helpful?

  1. Command Line

ssh

  • logout: exit or Ctrl-D (in shell it means end of input)

  • run remote command without going into the remote shell: ssh user@hostname "command"

  • ssh keys are stored in ~/.ssh

config file: .ssh/config

With the following in the config file, ssh dev will connect to the server.

Host dev
    User scott
    HostName orion.dev
    IdentityFile ~/.ssh/id_rsa

General structure of the config file

Host hostname1
    SSH_OPTION value
    SSH_OPTION value

Host hostname2
    SSH_OPTION value

Host *
    SSH_OPTION value

A single ssh command can match multiple sections in the config file. If multiple sections set the same SSH_OPTION, the first one wins. Therefore the generic settings (matching *) comes last.

Common ssh options includes:

  • Hostname

  • User

  • SendEnv

  • ProxyJump

  • IdentityFile

  • ForwardAgent

  • Port

  • AddKeysToAgent

  • UseKeychain

  • ServerAliveInterval

Refs

SCP

# Send local file to user home folder in server. Note the colon at the end.
scp localfile.txt scott@orion.dev:
# Send local file to a specific path in server
scp localfile.txt scott@orion.dev:/var/tmp
# Get file from server to current local folder
scp scott@orion.dev:filename.txt .
# use -r for directory

SSH Tunnel

Example: a remote database server (orion.dev:3306) only allows local access. On local machine we have a GUI tool, which can't connect to the remote database directly.

Solution: On local machine, use the following line to connect local port 9000 with server's port 3306 (via localhost:22, the port SSH uses). Note that the localhost in the following line refers to the remote server.

ssh -L 9000:localhost:3306 scott@orion.dev

Then the GUI tool can connect to localhost:9000 to access the remote database.

PreviousmakeNextgzip

Last updated 5 years ago

Was this helpful?

https://linuxize.com/post/using-the-ssh-config-file/
https://www.digitalocean.com/community/tutorials/how-to-configure-custom-connection-options-for-your-ssh-client