|
楼主 |
发表于 2004-11-24 16:25:18
|
显示全部楼层
Linux学习笔记(21)使用Openssh远程管理
使用Linux下的openssh
SSH采用了密文的形式在网络中传输数据,实现了更高的安全级别,是Telnet服务的安全替代品.
Openssh的安装程序
Openssh在Redhat中是默认安装的,
#rpm -qa|grep ssh
openssh-3.5p1-6
openssh-server-3.5p1-6
openssh-clients-3.5p1-6
openssh-3.5p1-6是Openssh的核心软件包,该软件包是Openssh服务起的客户端公用的,因此不论安装openssh服务器还是客户端都必需先安装该软件包.
openssh-server-3.5p1-6是openssh的服务器软件包,如当前linux主机需要作为openssh服务器,则需要安装该软件包.
openssh-clients-3.5p1-6是openssh的客户端软件包,如当前linux主机需要作为客户机连接到其他ssh服务器,则需要安装该软件包.
openssh的服务器配置
查询openssh服务器软件包中的文件
openssh服务器中包括服务器程序.配置文件.起动脚本和帮助文件
#rpm -ql openssh-server
/etc/pam.d/sshd
/etc/rc.d/init.d/sshd
/etc/ssh
/etc/ssh/sshd_config
/usr/libexec/openssh/sftp-server
/usr/sbin/sshd
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
/var/empty/sshd
openssh服务器中包括服务器程序.配置文件.起动脚本和帮助文件
查看openssh服务器的配置文件
openssh服务器的配置文件为/etc/ssh/sshd_config,文件中配置命令较多,但大部分不需要配置,保持其默认值就可以.
# more /etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.59 2002/09/25 11:17:16 markus 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
#Protocol 2,1
#ListenAddress 0.0.0.0
#ListenAddress ::
...
Openssh服务器配置文件的文件格式和具体配置指令可查阅手册页.
SSHD_CONFIG(5) BSD File Formats Manual SSHD_CONFIG(5)
NAME
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]sshd_config - OpenSSH SSH daemon configuration file
SYNOPSIS
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]/etc/ssh/sshd_config
DEscriptION
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]sshd reads configuration data from /etc/ssh/sshd_config (or the file
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]specified with -f on the command line). The file contains keyword-argu-
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]ment pairs, one per line. Lines starting with '#' and empty lines are
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]interpreted as comments.
Openssh服务器的起动与停止
查看Openssh服务器的状态
Openssh的启动脚本明称为sshd
# service sshd status
sshd (pid 2884) 正在运行...
起动openssh服务器
# service sshd start
启动 sshd [ 确定 ]
停止Openssh服务器
# service sshd stop
停止 sshd: [ 确定 ]
设置服务器默认起动
# chkconfig --list |grep ssh
sshd 0:关闭 1:关闭 2:启用 3:启用 4:关闭 5:启用 6:关闭
使用Openssh客户端连接SSH服务器
使用openssh-client可疑连接标准的ssh服务器.
# rpm -ql openssh-clients
/etc/ssh/ssh_config
/usr/bin/scp
/usr/bin/sftp
/usr/bin/slogin
/usr/bin/ssh
/usr/bin/ssh-add
/usr/bin/ssh-agent
/usr/bin/ssh-keyscan
/usr/share/man/man1/scp.1.gz
/usr/share/man/man1/sftp.1.gz
/usr/share/man/man1/slogin.1.gz
/usr/share/man/man1/ssh-add.1.gz
/usr/share/man/man1/ssh-agent.1.gz
/usr/share/man/man1/ssh-keyscan.1.gz
/usr/share/man/man1/ssh.1.gz
/usr/share/man/man5/ssh_config.5.gz
Openssh客户端配置文件
Openssh客户端的配置文件分为系统配置文件和用户配置文件两种,系统配置文件为系统中所有用户的默认ssh客户端配置,每个用户可疑自己定义自给ssh的用户配置文件作为该用户的ssh客户端配置值.
# more /etc/ssh/ssh_config
# $OpenBSD: ssh_config,v 1.16 2002/07/03 14:21:05 markus Exp $
# This is the ssh client system-wide configuration file. See
# ssh_config(5) for more information. This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.
# Configuration data is parsed as follows:
# 1. command line options
# 2. user-specific file
# 3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.
# Site-wide defaults for various options
...
openssh客户端与服务器配置文件比较
项目 配置文件全路径名称
Openssh服务器配置文件 /etc/ssh/sshd_config
Openssh客户端系统配置文件 /etc/ssh/ssh_config
Openssh客户端用户配置文件 $HOME/.ssh/config
Openssh客户端配置文件的文件格式和配置指令可疑查看该文件的手册页获得更多的信息.
#man ssh_config
SSH_CONFIG(5) BSD File Formats Manual SSH_CONFIG(5)
NAME
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]ssh_config - OpenSSH SSH client configuration files
SYNOPSIS
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]$HOME/.ssh/config
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]/etc/ssh/ssh_config
DEscriptION
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]ssh obtains configuration data from the following sources in the follow-
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]ing order:
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]1. command-line options
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]2. user's configuration file ($HOME/.ssh/config)
[$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp][$nbsp]3. system-wide configuration file (/etc/ssh/ssh_config)
...
使用ssh命令登录ssh服务器
ssh命令后跟所要登录的主机和用户登录的用户帐号,其形式为"用户名@主机地址"
# ssh [email protected]
The authenticity of host '197.2.6.31 (197.2.6.31)' can't be established.
RSA key fingerprint is 06:26:6f:e4:ae:31:a5:8a:6c:d1:17:23:89:ec:b8:22.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '197.2.6.31' (RSA) to the list of known hosts.
[email protected]'s password:
...
因为ssh协议采取加密数据传输,所以允许root直接登录,这与传统的telnet登录方式不同.
使用scp命令进行文件复制
scp命令类似于rcp命令,用于把一台主机的文件复制到另一主机.
scp命令的格式
scp 用户名@主机地址:文件全路径名
使用sftp命令下载文件
sftp命令类似于ftp命令,
命令格式为
sftp 用户名@主机地址
使用sftp命令登录的服务起主机需要运行Openssh服务起,sftp服务器程序即sftp-server是作为Openssh服务起的子系统存在的,需要使用openssh服务器配置文件sshd-config中加载sftp-server子系统
# rpm -ql openssh-server |grep sftp
/usr/libexec/openssh/sftp-server
/usr/share/man/man8/sftp-server.8.gz
要使用sftp-server功能需要在sshd-config文件中开启该子系统
# grep sftp /etc/ssh/sshd_config
Subsystem sftp /usr/libexec/openssh/sftp-server
在windows下的SSH客户端
在windows下可以使用PuTTY作为ssh客户端,cuteftp作为sftp的图形客户端. |
|