Say goodbye to Putty and Xshell: Using Cmder as an SSH shell under Windows, with ssh-key support. 与Putty和Xshell说再见:Windows下使用Cmder作为SSH工具

in #cn8 years ago (edited)


As introduced earlier(Chinese only) on this powerful command line / terminal tool under Windows, Cmder can do more. Today I'd like to share how to use Cmder as an SSH tool to login and manage your server.

  1. Requirement
    A full version of Cmder is required as SSH tool is coming with Git which is excluded in the mini version.
    You may get it from the official web site.

  2. How to use

    1. As SSH is built in with Cmder, you may use it anytime by typing:
      ssh <user>@ip [-p port]
      Here is an example:
      ssh [email protected] -p8888
      The -p option can be ignored if the port is 22 as default.
      Then you will be asked for typing the password. That's it.
    2. You might want to set a shortcut of this command line so you don't have to type it everytime and remember the IP adress
      I totally understand that because that's also what I am thinking. So you're lucky I already got the solution.

    Press Win+Alt+T to open the Startup -> Tasks window.

    Click on the + button on the left-bottom to define a new task.
    I'd like to name the task as {ssh::SERVERALIAS}, if you have more then one server, all the shortcuts will be under ssh group.

    Fill the following command.
    %ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe root@SERVER_ip -pSSHPORT
    Then you will get a shortcut in Create new console (see snapshot above).

  3. You might also tired on typing password everytime, wondering if you can set the ssh-key.
    Yes you can do this easily.
    We'll do this under Bash: Create new console -> bash -> bash

    1. Generate ssh-key
      Type command: ssh-keygen
      You will be asked to type a passphrase, just press Enter to leave it blank.

      Generating public/private rsa key pair.
      Enter file in which to save the key (/c/Users/daijia/.ssh/id_rsa):
      Enter passphrase (empty for no passphrase):
      Enter same passphrase again:
      Your identification has been saved in /c/Users/daijia/.ssh/id_rsa.
      Your public key has been saved in /c/Users/daijia/.ssh/id_rsa.pub.
      The key fingerprint is:
      The key's randomart image is:

    2. Upload the ssh-key to server
      Type command: ssh-copy-id <user>@SERVER_IP -pSSHPORT
      You will be asked to type the password of the user if everything goes smoothly.

      /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/c/Users/daijia/.ssh/id_rsa.pub"
      /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
      /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
      Number of key(s) added: 1
      Now try logging into the machine, with: "ssh -p 'SSHPORT' 'user@SERVER_IP'"
      and check to make sure that only the key(s) you wanted were added.

    3. It's done. Keep the private key file carefully.


前不久介绍了Windows下的强力命令行与终端工具Cmder,今天再与大家分享一下如何使用Cmder作为SSH登录与管理服务器。

  1. 需求
    需要完整版的Cmder,因为SSH是包含在Git工具包中的,mini版本不可用。
  2. 如何使用
    1. 因为Cmder自带了SSH,可以随时使用以下命令:
      ssh <user>@ip [-p port]
      例如:
      ssh [email protected] -p8888
      如果SSH的端口是默认的22,-p这个选项可以省略。之后会被要求输入密码。搞定。
    2. 你也许想要设置一个快捷方式,免得每次都输入命令,而且还要记住IP地址。
      我完全理解,因为我就是这么想的。你很幸运我已经搞定了。
      按住Win+Alt+T打开Startup -> Tasks设置窗口.

      点击左下方的+按钮来定义一个新的任务。
      我建议将任务名设置为{ssh::SERVERALIAS},这样当你有多个服务器需要管理的时候,会被统一收纳在ssh这个组中。

      填入下面的命令。
      %ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe root@SERVER_ip -pSSHPORT
      保存设置后,在Create new console中就会看到一个新的快捷方式了(见上面的截图)。
  3. 你可能觉得每次输入密码也很累,想通过设置ssh-key实现免密。
    实现起来也非常简单。
    这次我们需要在Bash下面操作:Create new console -> bash -> bash
    1. 生成ssh-key
      输入命令:ssh-keygen
      当要求输入passphrase的时候,直接回车即可。

      Generating public/private rsa key pair.
      Enter file in which to save the key (/c/Users/daijia/.ssh/id_rsa):
      Enter passphrase (empty for no passphrase):
      Enter same passphrase again:
      Your identification has been saved in /c/Users/daijia/.ssh/id_rsa.
      Your public key has been saved in /c/Users/daijia/.ssh/id_rsa.pub.
      The key fingerprint is:
      The key's randomart image is:

    2. 将 ssh-key 部署到服务器
      输入命令:ssh-copy-id <user>@SERVER_IP -pSSHPORT
      如果一切顺利,将被要求输入用户对应的登入密码。

      /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/c/Users/daijia/.ssh/id_rsa.pub"
      /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
      /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
      Number of key(s) added: 1
      Now try logging into the machine, with: "ssh -p 'SSHPORT' 'user@SERVER_IP'"
      and check to make sure that only the key(s) you wanted were added.

    3. 搞定了。记得保管好私钥文件。

Sort:  

不错,我很早就知道Cmder,不过一直没怎么用,以后可以试试

Coin Marketplace

STEEM 0.09
TRX 0.30
JST 0.034
BTC 113980.27
ETH 4102.38
USDT 1.00
SBD 0.60