OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现。SSH协议可以用来进行远程控制, 或在计算机之间传送文件。而实现此功能的传统方式,如telnet、ftp都是极为不安全的,并且会使用明文传送密码。OpenSSH提供了服务端后台程序和客户端工具,用来加密远程控件和文件传输过程中的数据,并由此来代替原来的类似服务。

ssh登陆方式分为两种:

1.基于口令

2.基于密钥

口令顾名思义,利用用户名和密码直接登录。

密钥的方式:相对好管理,不用记密码,并且安全性高。
————————————————
1、安装openssh

apt-get install openssh-server openssh-client

2、查看ssh服务状态
 

Ubuntu下ssh安装、配置及使用Ubuntu下ssh安装、配置及使用_linux

 

3、ssh配置的相关文件在/etc/ssh目录下

Ubuntu下ssh安装、配置及使用Ubuntu下ssh安装、配置及使用_ubuntu_02

 

ssh-config为client主配置文件 、sshd-config为service主配置文件  、ssh_host_dsa_key为版本2下DSA私匙、 ssh_host_dsa_key.pub为版本2下DSA公匙、ssh_host_rsa_key为版本1下RSA私匙、 ssh_host_rsa_key.pub为版本2下RSA公匙、

ssh服务器主要配置文件为/etc/ssh/sshd_config
 

Port 22                              #登入端口默认22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress :: 
#ListenAddress 0.0.0.0        #当服务器有多个ip,可配置服务器监听地址
Protocol 2                           #ssh服务器默认支持版本2
# HostKeys for protocol version 2           #设置加密密匙文件信息
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password  #禁止密码

#yes允许root登入 、#no不允许root登入、#without-password 停止使用root账号的密码验证、#forced-commands-onlyy#允许用公匙法验证root账号登入、#prohibit-password 禁止密码

StrictModes yes

RSAAuthentication yes  #是否允许使用rsa验证,仅适用于ssh版本1
PubkeyAuthentication yes   #是否允许使用公匙验证,仅适用于ssh版本2
 

#AuthorizedKeysFile     %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no    #是否允许空密码

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yesX11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no