当前位置:网站首页>sshd_ Discussion on permitrotlogin in config
sshd_ Discussion on permitrotlogin in config
2022-07-01 11:19:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
PermitRootLogin Options for
as everyone knows ,sshd_config yes sshd Configuration file for , among PermitRootLogin Can limit root User pass ssh Login method of , If login is prohibited 、 No password login 、 Only key login and open login are allowed , The following is a summary of the options :
Parameter category | Whether to allow ssh land | Login mode | Interaction shell |
|---|---|---|---|
yes | allow | There is no limit to | There is no limit to |
without-password | allow | In addition to the password | There is no limit to |
forced-commands-only | allow | Only keys are allowed | Only authorized commands are allowed |
no | Don't allow | N/A | N/A |
Of the above options ,yes and no Its function is obvious , It's just rude permission 、 prohibit root Users log in .without-password stay yes On the basis of , It's forbidden root Users log in with password .
forced-commands-only The function of
At present, only forced-commands-only This parameter is still unknown , The online reference materials only have the following descriptions :
If this option is set to “forced-commands-only”, root login with public key authentication will be allowed, but only if the command option has been specified (which may be useful for taking remote backups even if root login is normally not allowed). All other authentication methods are disabled for root.
In general, it means setting forced-commands-only after ,root Users are only allowed to log in with a key , Then only allow execution in command Commands allowed in , This mode is usually used for regular needs root The user login , But you only need to execute the specified script 、 Command situation , Such as periodic backup 、 Curing operation . But some of them command How to specify , There is no explanation here , With the attitude of breaking the casserole and asking the end , I searched all kinds of materials , Finally found command Where this option should be filled : That's it /root/.ssh/ In the catalog authorized_keys file . By default authorized_keys The file of is similar to the following :
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt0BETg9J6hZb5Kqxy+yfNtKHfwxUELz7PqGtGiM5eNb8DHC8kj02SCFoql5rpaecMGybWRiSK8/k+EsK7TMgd4O+p6WkNyLD3WZrmVzUEPaxAdYf1eeCQooTJ+B1TKXDNlF9t8xTVsHd67HmPWYU6i3+kaDSX7cbrz2ds2zUGSozj1UQ8AJDJMbGOqpjs3nVh2EpSDgY7znqmUDnygVPiM4c3OfEzs5iCxVd4ggpPhH8d0bwy8RmPsooxJYUY4rE1C5iWCvB7P810yUFB0OilxiX9AfZa9shC3n5bqaX0ioY1eC44hFFPL602fJyKMj6w/zxN5aIeFO03Sl9+FU4YQ== [email protected]
that command You need to load the beginning of the file :
command=”/bin/ps” ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt0BETg9J6hZb5Kqxy+yfNtKHfwxUELz7PqGtGiM5eNb8DHC8kj02SCFoql5rpaecMGybWRiSK8/k+EsK7TMgd4O+p6WkNyLD3WZrmVzUEPaxAdYf1eeCQooTJ+B1TKXDNlF9t8xTVsHd67HmPWYU6i3+kaDSX7cbrz2ds2zUGSozj1UQ8AJDJMbGOqpjs3nVh2EpSDgY7znqmUDnygVPiM4c3OfEzs5iCxVd4ggpPhH8d0bwy8RmPsooxJYUY4rE1C5iWCvB7P810yUFB0OilxiX9AfZa9shC3n5bqaX0ioY1eC44hFFPL602fJyKMj6w/zxN5aIeFO03Sl9+FU4YQ== [email protected]
This completes the configuration , Users who log in with this public key , Only execute /bin/ps Authority , And there is no interaction shell, It can only be executed once command The command .
So here comes the question
Careful friends may find , Because there is no interaction shell, therefore command Only one command can be added to , What should I do if I want to execute multiple commands ? This time is great shell It's time for the script to appear , Put the order that should be executed , All encapsulated in shell In the script , And then again command Write the absolute path of the script in . for example , Example script hi.sh:
echo This is huigher speaking
echo Now is `date`Then the actual effect of implementation is (ssh Connect to ssh The goal of the connection is alias):
[[email protected] .ssh]# ssh huigher
This is huigher speaking
Now is Sat Oct 29 16:13:36 CST 2016
Connection to 121.40.xxx.xxx closed.Saying without practicing the fake trick
Said so much , Maybe you are still a little confused , Then let's fight it
Configure public key and key
because forced-commands-only Pattern , Only key login is allowed , Then you need to configure the public key and key .
- On the local computer , Use command
ssh-keygen -t rsaTo generate a pair of keys and public keys , In the process, you need to select the directory where the key is stored (/YourPath/YourPrivateKey) And password ( In this case, it is empty ) - Place the generated public key on the remote server , Attach the public key to
~/.ssh/authorized_keysin , Such ascat id_rsa.pub >> ~/.ssh/authorized_keys - Make sure
~/.ssh/Directory permissions 700,~/.ssh/authorized_keysFile permissions are 600 - modify
/etc/ssh/sshd_configfile , Make sure the following lines are filled in RSAAuthentication yes PubkeyAuthentication yes
Set up forced-commands-only Related parameters
- modify
/etc/ssh/sshd_configfile , Add the following line : PermitRootLogin forced-commands-only - open
~/.ssh/authorized_keys, Find the last line of public key added , Add... At the frontcommand="/YourPath/YourFile", Such as :
command=”/usr/hi.sh” ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt0BETg9J6hZb5Kqxy+yfNtKHfwxUELz7PqGtGiM5eNb8DHC8kj02SCFoql5rpaecMGybWRiSK8/k+EsK7TMgd4O+p6WkNyLD3WZrmVzUEPaxAdYf1eeCQooTJ+B1TKXDNlF9t8xTVsHd67HmPWYU6i3+kaDSX7cbrz2ds2zUGSozj1UQ8AJDJMbGOqpjs3nVh2EpSDgY7znqmUDnygVPiM4c3OfEzs5iCxVd4ggpPhH8d0bwy8RmPsooxJYUY4rE1C5iWCvB7P810yUFB0OilxiX9AfZa9shC3n5bqaX0ioY1eC44hFFPL602fJyKMj6w/zxN5aIeFO03Sl9+FU4YQ== [email protected]
Closeout and testing
- restart sshd process
- Use... On the client ssh Connect :
ssh [email protected] -i /YourPath/YourPrivateKey, If it's too much trouble , It can also be directly on the client .ssh New under folder config The configuration file , Fill in ssh The host alias, So you can use it directlyssh huigherTo connect : Host huigher HostName 121.40.xxx.xxx Port 22 User root IdentityFile /YourPath/YourPrivateKey - The effect after configuration is as follows : [[email protected] .ssh]# ssh huigher This is huigher speaking Now is Sat Oct 29 16:13:36 CST 2016 Connection to 121.40.xxx.xxx closed.
- except
commandOrders other than , It can't be carried out , Besides, even interactive shell None , Not to mention carrying out orders , Therefore, the security is relatively high .
Last
This article was written in a hurry , There are inevitably mistakes and deficiencies , If you find , Please comment on , Thank you for !
Reference material
- https://www.novell.com/support/kb/doc.php?id=7007565
- http://askubuntu.com/questions/449364/what-does-without-password-mean-in-sshd-config-file
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/131634.html Link to the original text :https://javaforall.cn
边栏推荐
- What are the advantages and disadvantages of PHP
- 今天开户今天能买股票吗?在线开户是很安全么?
- 8款最佳实践,保护你的 IaC 安全!
- 妙啊!MarkBERT
- In June 2022, it was the first programming language?!
- Intel Labs annonce de nouveaux progrès en photonique intégrée
- CVPR 2022 | self enhanced unpaired image defogging based on density and depth decomposition
- 编译调试Net6源码
- Nordic nrf52832 flash 下载M4错误
- Intel Labs announces new progress in integrated photonics research
猜你喜欢

NeurIPS 2022 | 细胞图像分割竞赛正式启动!

Face detection and recognition system based on mtcnn+facenet

Neurips 2022 | cell image segmentation competition officially launched!

TEMPEST HDMI泄漏接收 4

Ten years of sharpening a sword: unveiling the secrets of ant group's observability platform antmonitor

BAIC bluevale: performance under pressure, extremely difficult period

妙啊!MarkBERT

名创拟7月13日上市:最高发行价22.1港元 单季净利下降19%

Oneconnect plans to be listed in Hong Kong on July 4: a loss of nearly 3 billion in two years, with a market capitalization evaporation of more than 90%

2022/6/28学习总结
随机推荐
Oneconnect plans to be listed in Hong Kong on July 4: a loss of nearly 3 billion in two years, with a market capitalization evaporation of more than 90%
关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
Mutual conversion of pictures in fluent uint8list format and pictures in file format
BAIC bluevale: performance under pressure, extremely difficult period
In June 2022, it was the first programming language?!
IPlImage的width和widthStep
银行卡借给别人是否构成犯罪
VScode快捷键(最全)[通俗易懂]
分享psd格式怎么预览的方法和psd文件缩略图插件[通俗易懂]
田溯宁投的天润云上市:市值22亿港元 年利润下降75%
Applymiddleware principle
Mysql的四个隔离级别是如何实现的 (简要)
Why must we move from Devops to bizdevops?
What are the advantages and disadvantages of PHP
CPI教程-异步接口创建及使用
Ten years of sharpening a sword: unveiling the secrets of ant group's observability platform antmonitor
获取键代码
优雅地翻转数组
Flip the array gracefully
The idea runs with an error command line is too long Shorten command line for...