Debian服务器下SSH的配置与问题

来源:互联网 发布:广州恒大全华班 知乎 编辑:程序博客网 时间:2024/05/16 04:45

参考

http://www.howtoforge.com/set-up-ssh-with-public-key-authentication-debian-etch

 

服务器端

 

1.在服务器端安装ssh

 

sudo aptitude install ssh

2.产生key

ssh-keygen -d

输入密码,然后产生id_dsa.pub id_dsa

3.将公匙放到服务器端

mkdir ~/.ssh

mv id_dsa.pub ~/.ssh/authorized_keys

sudo chmod 600 ~/.ssh/authorized_keys

同时将id_rsa拷到U盘。

Sudo chmod 600 ~/.ssh

4.配置SSH

cd /etc/ssh

cp sshd_config sshd_config.backup

vim sshd_config

PermitRootLogin no

PasswordAuthentication no

UsePAM no

这样关掉了root登陆和使用密码登陆。

5.重启SSH

sudo /etc/inti.d/ssh restart

 

 

客户端

我使用的putty

认证的地方不能直接用id_dsa,会报错误

Unable to use key file "id_rsa" (OpenSSH SSH-2 private key)

这是openssh使用的私钥格式与putty使用的私钥格式不一样。

这时候,打开puttygen.exe load id_dsa。然后保存private key。生成后缀是ppk的私钥。

如果报错误哦

Couldn't load private key (ciphers other than DES-EDE3-CBC not supported)

这是puttygen.exe的版本问题

在这里下载新的:

http://tartarus.org/~simon/putty-snapshots/x86/puttygen.exe

如果你直接用puttygen.exe生成一堆key。然后将public拷到服务器端的~/.ssh/authorized_keys,会报错:

Server Refused Our Key

http://www.walkernews.net/2009/03/22/how-to-fix-server-refused-our-key-error-that-caused-by-putty-generated-rsa-public-key/

这里有解决方法,没试过。最好的方法时用linuxssh-keygen产生密钥然后用puttygen.exe进行转换。