当前位置:Linux教程 - Linux - Linux系统中OpenSSH的安装和配置之三

Linux系统中OpenSSH的安装和配置之三

配置OpenSSH使其使用TCP-Wrappers inetd超级服务器

TCP-WRAPPERS用来启动和停止sshd1服务。当inetd运行的时候,它会从配置文件(默认为“/etc/inetd.conf”)中读入配置信息。在配置文件中每一行的不同项是用TAB或空格分开。

第一步

编辑“inetd.conf”文件(vi /etc/inetd.conf)并加入这一行:

ssh stream tcp nowait root /usr/sbin/tcpd sshd –i

注意:“-i”参数很重要,它说明sshd是被inetd运行的。在加入这一行后,通过发送一个SIGHUP信号(killall –HUP inetd)来更新“inetd.conf”文件。

[root@deep /root]? killall -HUP inetd

第二步

编辑“hosts.allow”文件(vi /etc/hosts.allow)并加入这一行:

sshd: 192.168.1.4 win.openarch.com

这一行表示IP地址为“192.168.1.4”,主机名为“win.openarch.com”的计算机允许用ssh访问服务器。

下面这些“daemon”字符串(用于TCP-WRAPPERS)被sshd1使用:

sshdfwd-X11 (允许/禁止X11转发).
sshdfwd-[port-number] (TCP转发).
sshdfwd-[port-name] (port-name在/etc/services中定义。用于TCP转发).

注意:如果准备使用ssh,一定要用在所有的服务器上。如果十台安全的服务器和一台不安全的服务器配在一起,也谈不上什么安全性。

更多的资料

如果想查找详细的资料可以用man命令查帮助页,读取相关信息:

$ man ssh (1) - OpenSSH secure shell client (remote login program)
$ man ssh [slogin] (1) - OpenSSH secure shell client (remote login program)
$ man ssh-add (1) - adds identities for the authentication agent
$ man ssh-agent (1) - authentication agent
$ man ssh-keygen (1) - authentication key generation
$ man sshd (8) - secure shell daemon

SSH1每用户配置

第一步

为本地服务器创建私有和公用密匙,执行下面的命令:

[root@deep]# su username
[username@deep]$ ssh-keygen1

举个例子,显示出来的结果可能是:

Initializing random number generator...
Generating p: ............................++ (distance 430)
Generating q: ......................++ (distance 456)
Computing the keys...
Testing the keys...
Key generation complete.
Enter file in which to save the key (/home/username/.ssh/identity): 【按下回车键】
Enter passphrase:
Enter the same passphrase again:
Your identification has been saved in /home/username/.ssh/identity.
Your public key is:
1024 37
14937757511251955533691120318477293862290049394715136511145806108870001764378494676831
29757784315853227236120610062314604405364871843677484233240919418480988907860997175244
46977589647127757030728779973708569993017043141563536333068888944038178461608592483844
590202154102756903055846534063365635584899765402181 [email protected]
Your public key has been saved in /home/username/.ssh/identity.pub

注意:如果有多个帐号需要为每个帐号创建一个密匙。

你可能要为下面的服务器创建密匙:

l Mail服务器

l Web服务器

l 网关服务器

这允许对这些服务器进行有限的访问,例如,不允许用Mail服务器的帐号访问Web服务器或网关服务器。这样可以增加整体的安全性,即使因为某种原因有一个密匙被泄密了,也不会影响到其它的服务器。

第二步

把本机的公用密匙(identity.pub)拷贝到远程主机的“/home/username/.ssh”目录下,例如,使用“authorized_keys”这个名字。

注意:拷贝文件的一个方法使用ftp命令,另一个办法是把公用密匙用email(包含“~/.ssh/identity.pub”文件的内容)发给系统管理员。

改变pass-phrase

用加上“-p”参数的“ssh-keygen”命令,在任何时候都可以改变pass-phrase。用下面的命令,改变pass-phrase:

[root@deep]# su username
[username@deep]$ ssh-keygen1 –p

Enter file key is in (/home/username/.ssh/identity): [按下回车键]
Enter old passphrase:
Key has comment ''[email protected]''
Enter new passphrase:
Enter the same passphrase again:
Your identification has been saved with the new passphrase.

OpenSSH用户工具

下面列出的是一些我们经常要用到的命令,当然还有很多其它的命令,更详细的信息可以查看man帮助页或其它文档。

ssh
ssh(Secure Shell)是用来登录远程计算机和在远程计算机上执行命令的程序。它是用来替代rlogin和rsh,以及在不安全的网络环境下在两台计算机之间提供安全和加密的信息交流。X11连接和TCP/IP端口可以被转发到一个安全的通道里。

用下面的命令,登录远程计算机:

[root@deep]# ssh [login_name] [hostname]

例如:

[root@deep]# ssh username www.openarch.com
[email protected]’s password:
Last login: Tue Oct 19 1999 18:13:00 -0400 from gate.openarch.com
Welcome to www.openarch.com on Deepforest.

[login_name]是用来登录ssh服务器的用户名,[hostname]是ssh服务器主机的地址。

scp
可以用这个命令把文件从本地计算机拷贝到远程计算机,或者反之,甚至可以在两台远程计算机之间用“scp”命令拷贝文件。把远程主机上的文件拷贝到当前目录的一个简单的方法如下。

用下面的命令把文件从远程主机拷贝到本地主机上:

[root@deep /]# su admin
[admin@deep /]$ scp -p [login_name@hostname]:/dir/for/file localdir/to/filelocation

例如:

[username@deep]$ scp -p username@mail:/etc/test1 /tmp
Enter passphrase for RSA key ''[email protected]'':
test1 | 2 KB | 2.0 kB/s | ETA: 00:00:00 | 100%

用下面的命令把文件从本地主机拷贝到远程主机上:

[root@deep /]# su admin
[admin@deep /]$ scp -p localdir/to/filelocation [username@hostname]:/dir/for/file

例如:

[username@deep]$ scp -p /usr/bin/test2 username@mail:/var/tmp
username@mail''s password:
test2 | 7 KB | 7.9 kB/s | ETA: 00:00:00 | 100%

注意:“-p”选项表示文件的改变和访问时间属性以及权限,在拷贝过程中被保留。通常是需要这样的。

安装到系统中的文件

# /etc/ssh
# /etc/ssh/ssh_config
# /etc/ssh/sshd_config
# /etc/ssh_host_key
# /etc/ssh_host_key.pub
# /usr/bin/ssh
# /usr/bin/slogin
# /usr/man/man1/ssh.1
# /usr/man/man1/scp.1
# /usr/man/man1/ssh-add.1
# /usr/man/man1/ssh-agent.1
# /usr/man/man1/ssh-keygen.1
# /usr/bin/scp
# /usr/bin/ssh-add
# /usr/bin/ssh-agent
# /usr/bin/ssh-keygen
# /usr/man/man1/slogin.1
# /usr/man/man8/sshd.8
# /usr/sbin/sshd

Windows平台上免费的SSH客户软件

Putty
Putty的主页:http://www.chiark.greenend.org.uk/~sgtatham/putty.html

Tera Term Pro and TTSSH
Tera Term Pro的主页:http://hp.vector.co.jp/authors/VA002416/teraterm.html

TTSSH Homepage:http://www.zip.com.au/~roca/download.html

版权说明

这篇文章翻译和改编自Gerhard Mourani的《Securing and Optimizing Linux: RedHat Edition》,原文及其版权协议请参考:http://www.openna.com/。

中文版的版权属于作者brimmer