linux SSH 相关操作

 * 查询 SSH是否安装或启动(centOS)

 

# rpm -qa|grep ssh

 这是一个已经安装并启动了SSH的输出信息。

openssh-5.3p1-123.el6_9.x86_64
libssh2-1.4.2-1.el6.x86_64
openssh-askpass-5.3p1-123.el6_9.x86_64
openssh-server-5.3p1-123.el6_9.x86_64
openssh-clients-5.3p1-123.el6_9.x86_64

*查询SSH进程

#ps -e|grep ssh

ps 是 Process Status 缩写。

 

*开启端口

开启22端口

#iptables -A INPUT -p tcp --dport 22 -j ACCEPT 

*修改SSH端口

#vi /etc/ssh/sshd_config

 

#       $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1

 

 Port 22,也可以在下面 增加其他的端口

Port 100

Port 101

...

SSH默认的端口是 22

* 命令netstat 常用参数

也可以使用netstat去查询一些参数

netstat -[atunlp]
-a 将目前系统上所有的连接、监听、Socket数据都列出来;
-t 列出tcp网络数据包的数据;
-u 列出udp网络数据包的数据;
-n 不列出进程的服务名称,以端口号来显示;
-l 列出目前正在网络坚挺的服务;
-p 列出该网络服务的进程PID。
例如:

  1. [root@linux ~]# netstat -anp | grep 1521  
  2. tcp        0      0 0.0.0.0:1521                0.0.0.0:*                   LISTEN      2542/tnslsnr          
  3. tcp        0      0 127.0.0.1:31115             127.0.0.1:1521              ESTABLISHED 2550/ora_pmon_orcl    
  4. tcp        0      0 127.0.0.1:1521              127.0.0.1:31115             ESTABLISHED 2542/tnslsnr          
  5. [root@linux ~]# netstat -an | grep 1521  
  6. tcp        0      0 0.0.0.0:1521                0.0.0.0:*                   LISTEN        
  7. tcp        0      0 127.0.0.1:31115             127.0.0.1:1521              ESTABLISHED  
  8. tcp        0      0 127.0.0.1:1521              127.0.0.1:31115             ESTABLISHED  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、查看SSH客户端版本 有的时候需要确认一下SSH客户端及其相应的版本号。使用ssh -V命令可以得到版本号。需要注意的是,Linux一般自带的是OpenSSH: 下面的例子即表明该系统正在使用OpenSSH: $ ssh -V OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003 下面的例子表明该系统正在使用SSH2: $ ssh -V ssh: SSH Secure Shell 3.2.9.1 (non-commercial version) on i686-pc-linux-gnu 2、用SSH登录到远程主机 当你第一次使用ssh登录远程主机时,会出现没有找到主机密钥的提示信息。输入"yes"后,系统会将远程主机的密钥加入到你的主目录下的 .ssh/hostkeys下,这样你就可以继续操作了。示例如下: 1 2 3 4 5 6 7 8 localhost$ ssh -l jsmith remotehost.example.com Host key not found from database. Key fingerprint: xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-jarde-tuxum You can get a public key‘s fingerprint by running % ssh-keygen -F publickey.pub on the keyfile. Are you sure you want to continue connecting (yes/no)? Yes Host key saved to /home/jsmith/.ssh2/hostkeys/key_22_remotehost.example.com.pub host key for remotehost.example.com, accepted by jsmith Mon May 26 2008 16:06:50 -0700 [email protected] password: remotehost.example.com$ 因为远程主机的密钥已经加入到ssh客户端的已知主机列表中,当你第二次登陆远程主机时,只需要你输入远程主机的登录密码即可。 1 2 3 localhost$ ssh -l jsmith remotehost.example.com [email protected] password: remotehost.example.com$ 由于各种原因,可能在你第一次登陆远程主机后,该主机的密钥发生改变,你将会看到一些警告信息。出现这种情况,可能有两个原因: o 系统管理员在远程主机上升级或者重新安装了SSH服务器 o 有人在进行一些恶意行为,等等。 在你输入“yes”之前呢,最佳的选择或许是联系你的系统管理员来分析为什么会出现主机验证码改变的信息,核对主机验证码是否正确。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 localhost$ ssh -l jsmith remotehost.example.com @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the- middle attack)! It is also possible that the host key has just been changed. Please contact your system administrator. Add correct host key to ―/home/jsmith/.ssh2/hostkeys/key_22_remotehost.example.com.pub‖ to get rid of this message. Received server key's fingerprint: xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-arde-tuxum You can get a publ

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值