zoukankan      html  css  js  c++  java
  • Xshell5 访问虚拟机Ubuntu16.04

    1.Ubuntu安装telnet

    安装openbsd-inetd
    sudo apt-get install openbsd-inetd
    
    安装telnetd
    sudo apt-get install telnetd
    
    重启openbsd-inetd
    sudo /etc/init.d/openbsd-inetd restart
    
    查看telnet运行状态
    sudo netstat -a | grep telnet
    
    登录
    telnet IP address

    访问:

    hongdada@ubuntu:~$ telnet 192.168.1.203 22
    Trying 192.168.1.203...
    telnet: Unable to connect to remote host: Connection refused

    使用 netstat -napt查看端口是否被监听

    hongdada@ubuntu:~$ netstat -napt
    (并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)
    激活Internet连接 (服务器和已建立连接的)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:23              0.0.0.0:*               LISTEN      -               
    tcp        0      0 192.168.1.203:44850     124.192.164.34:80       ESTABLISHED 5200/chrome     
    tcp        0      0 192.168.1.203:39874     119.75.213.61:443       ESTABLISHED 

    发现22并没有被监听

    安装OpenSSH

    hongdada@ubuntu:~$ sudo apt-get install openssh-server
    [sudo] hongdada 的密码: 
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    下列软件包是自动安装的并且现在不需要了:
      linux-headers-4.4.0-21 linux-headers-4.4.0-21-generic linux-headers-4.4.0-62
      linux-headers-4.4.0-62-generic linux-headers-4.4.0-63
      linux-headers-4.4.0-63-generic linux-headers-4.4.0-64
      linux-headers-4.4.0-64-generic linux-headers-4.4.0-66
      linux-headers-4.4.0-66-generic linux-image-4.4.0-21-generic
      linux-image-4.4.0-62-generic linux-image-4.4.0-63-generic
      linux-image-4.4.0-64-generic linux-image-4.4.0-66-generic
      linux-image-extra-4.4.0-21-generic linux-image-extra-4.4.0-62-generic
      linux-image-extra-4.4.0-63-generic linux-image-extra-4.4.0-64-generic
      linux-image-extra-4.4.0-66-generic
    使用'sudo apt autoremove'来卸载它(它们)。
    将会同时安装下列软件:
      ncurses-term openssh-client openssh-sftp-server ssh-import-id
    建议安装:
      ssh-askpass libpam-ssh keychain monkeysphere rssh molly-guard
    下列【新】软件包将被安装:
      ncurses-term openssh-server openssh-sftp-server ssh-import-id
    下列软件包将被升级:
      openssh-client
    升级了 1 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 136 个软件包未被升级。
    需要下载 1,222 kB 的归档。
    解压缩后会消耗 5,145 kB 的额外空间。
    您希望继续执行吗? [Y/n] Y
    获取:1 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 openssh-client amd64 1:7.2p2-4ubuntu2.2 [587 kB]
    获取:2 http://mirrors.aliyun.com/ubuntu xenial/main amd64 ncurses-term all 6.0+20160213-1ubuntu1 [249 kB]
    获取:3 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 openssh-sftp-server amd64 1:7.2p2-4ubuntu2.2 [38.7 kB]
    获取:4 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 openssh-server amd64 1:7.2p2-4ubuntu2.2 [338 kB]
    获取:5 http://mirrors.aliyun.com/ubuntu xenial/main amd64 ssh-import-id all 5.5-0ubuntu1 [10.2 kB]
    已下载 1,222 kB,耗时 1秒 (1,221 kB/s)   
    正在预设定软件包 ...
    (正在读取数据库 ... 系统当前共安装有 383933 个文件和目录。)
    正准备解包 .../openssh-client_1%3a7.2p2-4ubuntu2.2_amd64.deb  ...
    正在将 openssh-client (1:7.2p2-4ubuntu2.2) 解包到 (1:7.2p2-4ubuntu2.1) 上 ...
    正在选中未选择的软件包 ncurses-term。
    正准备解包 .../ncurses-term_6.0+20160213-1ubuntu1_all.deb  ...
    正在解包 ncurses-term (6.0+20160213-1ubuntu1) ...
    正在选中未选择的软件包 openssh-sftp-server。
    正准备解包 .../openssh-sftp-server_1%3a7.2p2-4ubuntu2.2_amd64.deb  ...
    正在解包 openssh-sftp-server (1:7.2p2-4ubuntu2.2) ...
    正在选中未选择的软件包 openssh-server。
    正准备解包 .../openssh-server_1%3a7.2p2-4ubuntu2.2_amd64.deb  ...
    正在解包 openssh-server (1:7.2p2-4ubuntu2.2) ...
    正在选中未选择的软件包 ssh-import-id。
    正准备解包 .../ssh-import-id_5.5-0ubuntu1_all.deb  ...
    正在解包 ssh-import-id (5.5-0ubuntu1) ...
    正在处理用于 man-db (2.7.5-1) 的触发器 ...
    正在处理用于 ufw (0.35-0ubuntu2) 的触发器 ...
    正在处理用于 systemd (229-4ubuntu16) 的触发器 ...
    正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
    正在设置 openssh-client (1:7.2p2-4ubuntu2.2) ...
    正在设置 ncurses-term (6.0+20160213-1ubuntu1) ...
    正在设置 openssh-sftp-server (1:7.2p2-4ubuntu2.2) ...
    正在设置 openssh-server (1:7.2p2-4ubuntu2.2) ...
    Creating SSH2 RSA key; this may take some time ...
    2048 SHA256:Fggzi+si7eAimez/6obJ9ykFiTnBvfOkQk1D3G198KI root@ubuntu (RSA)
    Creating SSH2 DSA key; this may take some time ...
    1024 SHA256:l1qkn+YwdNyBnNVurPG2Qg22CrVL/41VAyqqZr6I1Lc root@ubuntu (DSA)
    Creating SSH2 ECDSA key; this may take some time ...
    256 SHA256:QCmE/BZXVtoThmb0gmxbRD7+vzTX+cbVud6e9EXW2cE root@ubuntu (ECDSA)
    Creating SSH2 ED25519 key; this may take some time ...
    256 SHA256:1D0iLpOURGJF4sMTzCoittU3V27FyXO72hr/HFJtO2U root@ubuntu (ED25519)
    正在设置 ssh-import-id (5.5-0ubuntu1) ...
    正在处理用于 systemd (229-4ubuntu16) 的触发器 ...
    正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
    正在处理用于 ufw (0.35-0ubuntu2) 的触发器 ...
    hongdada@ubuntu:~$ ps -e|grep ssh
      6549 ?        00:00:00 sshd
    hongdada@ubuntu:~$ netstat -antp|grep 22
    (并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
    tcp        1      0 192.168.1.203:41412     23.219.133.226:443      CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:42228     117.122.217.6:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:42222     117.122.217.6:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:43846     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:51622     124.192.164.48:80       CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:43850     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        0      0 192.168.1.203:40188     115.28.122.210:80       TIME_WAIT   -               
    tcp        0      0 192.168.1.203:43802     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp       32      0 192.168.1.203:41390     23.219.133.226:443      CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:42224     117.122.217.6:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:42226     117.122.217.6:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:43824     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:34240     13.124.96.226:80        CLOSE_WAIT  5200/chrome     
    tcp       32      0 192.168.1.203:41394     23.219.133.226:443      CLOSE_WAIT  5200/chrome     
    tcp        0      0 192.168.1.203:43854     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:43804     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:51004     119.75.222.191:80       CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:45140     52.221.26.127:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:52822     59.110.88.38:80         CLOSE_WAIT  5200/chrome     
    tcp        0      1 192.168.1.203:43178     119.75.222.22:80        FIN_WAIT1   -               
    tcp        1      0 192.168.1.203:42206     117.122.217.6:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:34306     13.124.96.226:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:43164     119.75.222.22:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:42218     117.122.217.6:80        CLOSE_WAIT  5200/chrome     
    tcp        0      0 192.168.1.203:43848     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:43176     119.75.222.22:80        CLOSE_WAIT  5200/chrome     
    tcp        0      0 192.168.1.203:43840     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:34238     13.124.96.226:80        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:43412     124.14.17.221:80        CLOSE_WAIT  5200/chrome     
    tcp        0      0 192.168.1.203:41392     23.219.133.226:443      ESTABLISHED 5200/chrome     
    tcp        0      1 192.168.1.203:51006     119.75.222.191:80       FIN_WAIT1   -               
    tcp        0      0 192.168.1.203:43826     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:43844     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp       32      0 192.168.1.203:41396     23.219.133.226:443      CLOSE_WAIT  5200/chrome     
    tcp        0      0 192.168.1.203:43800     180.76.22.33:443        CLOSE_WAIT  5200/chrome     
    tcp        1      0 192.168.1.203:34236     13.124.96.226:80        CLOSE_WAIT  5200/chrome     
    tcp        0      0 192.168.1.203:58226     203.208.43.90:80        ESTABLISHED 5200/chrome     
    tcp        0      0 192.168.1.203:58224     203.208.43.90:80        ESTABLISHED 5200/chrome     
    tcp        1      0 192.168.1.203:45142     52.221.26.127:80        CLOSE_WAIT  5200/chrome     
    tcp6       0      0 :::22                   :::*                    LISTEN      -               
    hongdada@ubuntu:~$ telnet 127.0.0.1 22
    Trying 127.0.0.1...
    Connected to 127.0.0.1.
    Escape character is '^]'.
    SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
    
    Protocol mismatch.
    Connection closed by foreign host.
    hongdada@ubuntu:~$ 
    View Code

    Ubuntu 默认安装了client端,但是没有安装Server端,所以现在要安装openssh-server

    sudo apt-get install openssh-server

    安装以后查看22端口是否被监听

    netstat -antp|grep 22

    如果只有ssh-agent那ssh-server还没有启动,需要/etc/init.d/ssh start或者service ssh start,如果看到sshd那说明ssh-server已经启动了。

    ssh-server配置文件位于/ etc/ssh/sshd_config,在这里可以定义SSH的服务端口,默认端口是22,你可以自己定义成其他端口号,如222。然后重启SSH服务:

    sudo /etc/init.d/ssh restart

    现在使用xshell访问Ubuntu 

    连接:

    Xshell 5 (Build 1124)
    Copyright (c) 2002-2017 NetSarang Computer, Inc. All rights reserved.
    
    Type `help' to learn how to use Xshell prompt.
    [c:~]$ 
    
    Connecting to 192.168.1.203:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.
    
    Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-83-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    
    140 个可升级软件包。
    0 个安全更新。
    
    Last login: Tue Jul 18 23:51:42 2017 from 192.168.1.222
    hongdada@ubuntu:~$ 

    http://www.linuxidc.com/Linux/2014-02/97218.htm

  • 相关阅读:
    在MPTCP中引入流量监控——bwm-ng的使用说明
    Ubuntu下配置MPTCP
    实现两台MPTCP主机之间的通信——VSFTPD的配置与使用
    Google 辟谣,Android 和 Chrome OS 不合并
    paper-7
    计算机网络方面国际三大顶尖会议
    谷歌物联网操作系统Android Things揭开面纱
    张纯如
    Android binder机制之 5 --(创建binder服务)
    【BZOJ 1491】[NOI2007]社交网络
  • 原文地址:https://www.cnblogs.com/hongdada/p/7203489.html
Copyright © 2011-2022 走看看