当前位置:   article > 正文

Linux安装ssh |Ubuntu安装ssh |Ubuntu配置ssh_sudo apt-get install openssh-server

sudo apt-get install openssh-server

本文仅作为个人备忘使用。在折腾seafile过程中由于需要使用docker装linux作为服务器,整合一点远程ssh的安装步骤。

Ubuntu安装ssh

1.更新

sudo apt-get update
  • 1

2.安装openssh服务

sudo apt-get install openssh-server 
  • 1

3.安装openssh客户端

sudo apt-get install openssh-client 
  • 1

4.启动ssh服务

sudo service ssh start
  • 1

5.打开sshd服务端配置文件

sudo vim /etc/ssh/sshd_config
  • 1

备选

sudo  gedit  /etc/ssh/sshd_config
sudo  vi   /etc/ssh/sshd_config

##没有安装vim可以执行安装命令
sudo apt-get install vim
  • 1
  • 2
  • 3
  • 4
  • 5

注意:root用户执行命令时请删去sudo

6.修改文件配置:
Port为端口号,默认为22,可以根据需要自行修改。
PermitRootLogin prohibit-password请修改为PermitRootLogin yes,否则无法使用密码登陆.
其他配置请根据注释按需修改,#开头的行认为无效,若要修改请先将#去掉。

文件配置:
简版:

#/etc/ssh/sshd_config

`#Port 22` --改为--> `Port 22`
`#PermitRootLogin prohibit-password` --改为--> `PermitRootLogin yes`
添加一行`PasswordAuthentication yes`
  • 1
  • 2
  • 3
  • 4
  • 5

详版:

#/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 
PasswordAuthentication yes 
PermitRootLogin prohibit-password  #禁止密码,此处请改为yes

#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    #是否允许空密码
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 开机自动启动ssh命令
	sudo systemctl enable ssh
  • 1
  • 关闭ssh开机自动启动命令
	sudo systemctl disable ssh   
  • 1
  • 单次开启ssh
	sudo systemctl start ssh   
  • 1
  • 单次关闭ssh
	sudo systemctl stop ssh     
  • 1
  • 设置好后重启系统
	reboot   
  • 1
  • 查看ssh是否启动,看到Active: active (running)即表示成功
	 sudo systemctl status ssh
  • 1

单用户设置用户密码

# passwd `你的用户名`
	 passwd root
  • 1
  • 2

注意:linux及unix绝大部分场景输入密码,密码内容不可见。尽管看不见,输入是有效的,直接输入就行了。

root@admin:/# passwd root                                                                                                                 
New password:                                                                                                                                    
Retype new password:                                                                                                                             
passwd: password updated successfully                                                                                                            
root@admin:/#         
  • 1
  • 2
  • 3
  • 4
  • 5

以下仅针对小白用户,大佬请自动跳过
首次安装ssh可能会出现选择地区和时区
Geographic area: 为选择地区,这里我们选6.亚洲
Time zone:为选择时区,这里我们可以选70.上海
如果有些系统还有一步选择,给出不全的时区,直接也键入70即可

……
Need to get 20.2 MB of archives.                                                                                                                 
After this operation, 88.2 MB of additional disk space will be used.                                                                             
Do you want to continue? [Y/n] y                                                                                                                 
Get:1 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 libapparmor1 amd64 2.13.3-7ubuntu5.1 [34.1 kB]                                   
Get:2 http://mirrors.aliyun.com/ubuntu focal/main amd64 libcap2 amd64 1:2.32-1 [15.9 kB]                                                         
Get:3 http://mirrors.aliyun.com/ubuntu focal/main amd64 libargon2-1 amd64 0~20171227-0.2 [19.2 kB]
……
……
……
Configuring tzdata                                                                                                                               
------------------                                                                                                                               
                                                                                                                                                
Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities,    
representing the time zones in which they are located.                                                                                           
                                                                                                                                               
 1. Africa   3. Antarctica  5. Arctic  7. Atlantic  9. Indian    11. SystemV  13. Etc                                                           
 2. America  4. Australia   6. Asia    8. Europe    10. Pacific  12. US                                                                         
Geographic area: 6                                                                                                                               
                                                                                                                                                
Please select the city or region corresponding to your time zone.                                                                                
                                                                                                                                                
 1. Aden      13. Barnaul     25. Dushanbe     37. Jerusalem     49. Macau         61. Pyongyang      73. Taipei         85. Vientiane          
 2. Almaty    14. Beirut      26. Famagusta    38. Kabul         50. Magadan       62. Qatar          74. Tashkent       86. Vladivostok        
 3. Amman     15. Bishkek     27. Gaza         39. Kamchatka     51. Makassar      63. Qostanay       75. Tbilisi        87. Yakutsk            
 4. Anadyr    16. Brunei      28. Harbin       40. Karachi       52. Manila        64. Qyzylorda      76. Tehran         88. Yangon             
 5. Aqtau     17. Chita       29. Hebron       41. Kashgar       53. Muscat        65. Rangoon        77. Tel_Aviv       89. Yekater
 6. Aqtobe    18. Choibalsan  30. Ho_Chi_Minh  42. Kathmandu     54. Nicosia       66. Riyadh         78. Thimphu        90. Yerevan            
 7. Ashgabat  19. Chongqing   31. Hong_Kong    43. Khandyga      55. Novokuznetsk  67. Sakhalin       79. Tokyo                                 
 8. Atyrau    20. Colombo     32. Hovd         44. Kolkata       56. Novosibirsk   68. Samarkand      80. Tomsk                                 
 9. Baghdad   21. Damascus    33. Irkutsk      45. Krasnoyarsk   57. Omsk          69. Seoul          81. Ujung_Pandang                         
 10. Bahrain  22. Dhaka       34. Istanbul     46. Kuala_Lumpur  58. Oral          70. Shanghai       82. Ulaanbaatar                           
 11. Baku     23. Dili        35. Jakarta      47. Kuching       59. Phnom_Penh    71. Singapore      83. Urumqi                                
 12. Bangkok  24. Dubai       36. Jayapura     48. Kuwait        60. Pontianak     72. Srednekolymsk  84. Ust-Nera                              
Time zone: 70                                                                                                                                    
                                                                                                                                               
                                                                                                                                                
Current default time zone: 'Asia/Shanghai'                                                                                                       
Local time is now:      Sun Aug 28 19:23:04 CST 2022.                                                                                            
Universal Time is now:  Sun Aug 28 11:23:04 UTC 2022.                                                                                            
Run 'dpkg-reconfigure tzdata' if you wish to change it.                                                                                          
                                                                                                                                               
Setting up python3-six (1.14.0-2) ...                                                                                                            
Setting up libglib2.0-data (2.64.6-1~ubuntu20.04.4) ...                                                                                          
Setting up python3-chardet (3.0.4-4build1) ...                                                                                                   
Setting up libwrap0:amd64 (7.6.q-30) ...                                                                                                         
Setting up python3-certifi (2019.11.28-1) ...                                                                                                    
Setting up libx11-data (2:1.6.9-2ubuntu1.3) ...     
……
……
……
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/185196
推荐阅读
相关标签
  

闽ICP备14008679号