linux远程命令工具 linux远程管理命令( 三 )


如果设置了COMMAND,表示使用username账户登录远程主机执行一次指定的命令并返回结果 , 不会停留在远程主机上;
[root@www ~]# ssh 192.168.0.110 #使用root用户登录;
The authenticity of host '192.168.0.110 (192.168.0.110)' can't be established.
RSA key fingerprint is 01:2e:43:cc:bc:1d:f1:e5:f0:f4:89:78:74:a9:49:44.
Are you sure you want to continue connecting (yes/no)? yes #第一次连接,需手动进行确认;
Warning: Permanently added '192.168.0.110' (RSA) to the list of known hosts.
root@192.168.0.110's password: #输入远程主机root账户的密码;
Last login: Mon May 11 16:44:52 2015 from 192.168.0.104
[root@mailCentOS6 ~]# #登录成功了,远程主机名为mailCentOS6;
[root@mailCentOS6 ~]# ls #显示远程主机root家目录下的文件;
2.sh boot.iso install.log sdb.mbr test1
anaconda-ks.cfg crontab install.log.syslog \temp\test
[root@mailCentOS6 ~]# exit #退出登录;
logout
Connection to 192.168.0.110 closed.
[root@www ~]# ssh root@192.168.0.110 ls #使用root登录远程主机,执行一次ls命令,返回结果便退出;
root@192.168.0.110's password: #第二次连接 , 就不需要输入yes了,直接输入密码即可;
2.sh
anaconda-ks.cfg
boot.iso
crontab
install.log
install.log.syslog
sdb.mbr
\temp\test
test1
[root@www ~]# #看到了吗,我们当前并没有登录在远程主机;
【OpenSSH服务器端组件-sshd】
配置文件:/etc/ssh/sshd_config(通过修改此文件可以修改ssh的默认监听端口与其他参数)
服务脚本:/etc/rc.d/init.d/sshd
服务启动|停止|重启:serveice sshd start|stop|restart
脚本配置文件:/etc/sysconfig/sshd
配置参数
# man sshd_config 查看配置参数的说明;
# vim /etc/sysconfig/sshd 通过编辑配置文件来修改配置参数;
#+空格+文字:以此格式开头的行表示改行为注释说明;
#+文字:以此格式开头的行表示可启用选项,不改变则表示使用该选项的默认设置,反之使用设定值“#”要去掉哦!
例:#Port 22 如不去掉#且22不变,表示使用默认的22号端口;
若把#Port 22改成port 7777,表示把sshd的监听端口改成7777;
注意:修改参数与配置后,必须重启服务(service sshd restart).
经常需要修改的参数:
[root@www ~]# cat /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 #修改默认监听的端口;
port 7777 #把sshd的监听端口改成7777;
#AddressFamily any #监听的地址家族,指定是监听在IPV4上还是IPV6上,any表示所有;
#ListenAddress 0.0.0.0 #指定监听的地址 (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
#HostKey /etc/ssh/ssh_host_key #使用shhv1用到的主机密钥;
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024 #密钥长度;
# Logging

推荐阅读