输入grep "^scp" /etc/ssh/sshd_config之后什么也没显示

时间: 2023-09-29 19:06:44 浏览: 52
如果在执行 `grep "^scp" /etc/ssh/sshd_config` 命令后没有显示任何内容,说明在 SSH 服务器的配置文件 `/etc/ssh/sshd_config` 中没有包含以 "scp" 开头的配置行。 这意味着树莓派上的 SSH 服务器配置文件中没有明确启用或禁用 scp 服务。默认情况下,树莓派上的 SSH 服务器应该已经启用了 scp 协议。 你可以尝试使用 scp 命令来进行文件传输,如果成功传输文件,则说明 scp 服务已经启用。如果遇到任何问题,请确保你已经正确安装和配置了 OpenSSH 服务器。 另外,你也可以手动编辑 `/etc/ssh/sshd_config` 文件,在文件中添加或修改以下行来启用或禁用 scp 服务: ``` # 启用 scp 服务 Subsystem sftp /usr/lib/openssh/sftp-server ``` 确保在编辑配置文件之后重新启动 SSH 服务器,以使更改生效: ``` sudo service ssh restart ``` 请注意,对于任何对系统配置文件的更改,都要小心谨慎,并备份原始文件以防万一。
相关问题

逐条注释 ``` if grep -q "Protocol" /etc/ssh/sshd_config then sed -i '/Protocol/s/^#//' /etc/ssh/sshd_config sed -i "s/Protocol.*/Protocol 2/g" /etc/ssh/sshd_config else echo 'Protocol 2' >> /etc/ssh/sshd_config fi if grep -q "PrintMotd" /etc/ssh/sshd_config then sed -i '/PrintMotd/s/^#//' /etc/ssh/sshd_config sed -i "s/PrintMotd.*/PrintMotd yes/g" /etc/ssh/sshd_config else echo "PrintMotd yes" >> /etc/ssh/sshd_config fi service sshd restart systemctl restart sshd.service ```

这段脚本的作用是修改/etc/ssh/sshd_config文件中的SSH配置,并重新启动SSH服务。具体解释如下: ```shell if grep -q "Protocol" /etc/ssh/sshd_config then sed -i '/Protocol/s/^#//' /etc/ssh/sshd_config sed -i "s/Protocol.*/Protocol 2/g" /etc/ssh/sshd_config else echo 'Protocol 2' >> /etc/ssh/sshd_config fi ``` - 检查/etc/ssh/sshd_config文件中是否存在"Protocol"这一行。 - 如果存在,则使用sed命令将该行的行首的注释符号#去掉,即取消注释。 - 然后使用sed命令将该行的值修改为"Protocol 2",即设置SSH协议版本为2。 - 如果不存在,则在文件末尾添加一行"Protocol 2"。 ```shell if grep -q "PrintMotd" /etc/ssh/sshd_config then sed -i '/PrintMotd/s/^#//' /etc/ssh/sshd_config sed -i "s/PrintMotd.*/PrintMotd yes/g" /etc/ssh/sshd_config else echo "PrintMotd yes" >> /etc/ssh/sshd_config fi ``` - 检查/etc/ssh/sshd_config文件中是否存在"PrintMotd"这一行。 - 如果存在,则使用sed命令将该行的行首的注释符号#去掉,即取消注释。 - 然后使用sed命令将该行的值修改为"PrintMotd yes",即启用SSH登录时显示欢迎信息。 - 如果不存在,则在文件末尾添加一行"PrintMotd yes"。 ```shell service sshd restart systemctl restart sshd.service ``` - 重新启动SSH服务,使配置生效。这两行命令可能根据Linux发行版的不同而有所区别,用于重启SSH服务。

if grep -q "PrintMotd" /etc/ssh/sshd_config then sed -i '/PrintMotd/s/^#//' /etc/ssh/sshd_config sed -i "s/PrintMotd.*/PrintMotd yes/g" /etc/ssh/sshd_config else echo "PrintMotd yes" >> /etc/ssh/sshd_config fi service sshd restart systemctl restart sshd.service find / -name .rhosts |xargs rm -rf find / -name .hosts.equiv |xargs rm -rf find / -name .netrc |xargs rm -rf if [ -f "/etc/ftpusers" ];then echo 'root' >> /etc/ftpusers fi

以下是将这些命令转换为Python代码的示例: ```python import subprocess sshd_config_file = '/etc/ssh/sshd_config' ftpusers_file = '/etc/ftpusers' # Update PrintMotd in sshd_config file if subprocess.call('grep -q "PrintMotd" /etc/ssh/sshd_config', shell=True) == 0: subprocess.call("sed -i '/PrintMotd/s/^#//' /etc/ssh/sshd_config", shell=True) subprocess.call("sed -i 's/PrintMotd.*/PrintMotd yes/g' /etc/ssh/sshd_config", shell=True) else: subprocess.call("echo 'PrintMotd yes' >> /etc/ssh/sshd_config", shell=True) # Restart sshd service subprocess.call('service sshd restart', shell=True) subprocess.call('systemctl restart sshd.service', shell=True) # Remove .rhosts, .hosts.equiv and .netrc files subprocess.call('find / -name .rhosts | xargs rm -rf', shell=True) subprocess.call('find / -name .hosts.equiv | xargs rm -rf', shell=True) subprocess.call('find / -name .netrc | xargs rm -rf', shell=True) # Update ftpusers file if subprocess.call('[ -f "/etc/ftpusers" ]', shell=True) == 0: subprocess.call("echo 'root' >> /etc/ftpusers", shell=True) ``` 上述代码首先检查是否存在`/etc/ssh/sshd_config`文件中的`PrintMotd`行,如果存在,则将其注释去除,并将其值设置为`yes`。如果不存在,则在文件末尾添加一行`PrintMotd yes`。 然后,通过执行`service sshd restart`和`systemctl restart sshd.service`命令来重新启动sshd服务。 接下来,使用`find`命令查找并删除系统中的`.rhosts`、`.hosts.equiv`和`.netrc`文件。 最后,检查是否存在`/etc/ftpusers`文件。如果文件存在,则在文件末尾添加一行`root`。 请确保你具有足够的权限来执行这些操作,并将需要修改的文件路径正确添加到`sshd_config_file`和`ftpusers_file`变量中。运行代码后,命令将被执行。

相关推荐

逐条注释 getenforce setenforce 0 cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.old.service sed -i -e 's/^Type=.*/Type=simple/g' -e '/ExecStart=/{s/\/usr\/sbin\/sshd/\/usr\/local\/sbin\/sshd/g}' /usr/lib/systemd/system/sshd.service sed -i "s/GSSAPIAuthentication/#GSSAPIAuthentication/" /etc/ssh/sshd_config sed -i "s/GSSAPICleanupCredentials/#GSSAPICleanupCredentials/" /etc/ssh/sshd_config sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/" /etc/ssh/sshd_config sed -i "s/#UsePAM yes/UsePAM yes/" /etc/ssh/sshd_config chmod 600 /etc/ssh/ssh_host_rsa_key chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 600 /etc/ssh/ssh_host_ed25519_key mv /usr/local/sbin/sshd /usr/local/sbin/sshd.old202211 mv /lib64/libcrypto.so.1.1 /lib64/libcrypto.so.1.1.old202211 mv /srv/libcrypto.so.1.1 /lib64/ mv /srv/sshd /usr/local/sbin/ chmod 755 /usr/local/sbin/sshd chmod 755 /lib64/libcrypto.so.1.1 systemctl daemon-reload systemctl restart sshd.service source /etc/profile sshd -V useradd secure echo 'Ofm#6%3%fm0IWH'|passwd --stdin secure echo "secure ALL=(ALL) ALL" >> /etc/sudoers sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config service sshd restart systemctl daemon-reload systemctl restart sshd.service sed -i "s/secure ALL=(ALL) ALL/secure ALL=(ALL) NOPASSWD: ALL/" /etc/sudoers chage -M 99999 secure sleep 2 useradd aqassoc echo 'dAxgDt^7LT' | passwd --stdin aqassoc mkdir /batshell chown -R aqassoc:aqassoc /batshell echo 'aqassoc ALL=(ALL) NOPASSWD:ALL,!/bin/su,!/sbin/init,!/sbin/shutdown,!/sbin/halt,!/sbin/reboot,!/usr/sbin/visudo,!/usr/bin/passwd' >> /etc/sudoers sh /srv/script.sh sleep 2 tar -xvf /srv/ssl-1.1.1o* -C /srv/ mv /usr/bin/openssl /usr/bin/openssl.old mv /usr/include/openssl /usr/include/openssl.old cp /etc/ld.so.conf /etc/ld.so.conf.old ln -s /srv/ssl-1.1.1o/bin/openssl /usr/bin/openssl ln -s /srv/ssl-1.1.1o/include/openssl /usr/include/openssl srvlib=cat /etc/ld.so.conf | grep '/srv/ssl-1.1.1o/lib/' | wc -l if [ $srvlib -eq 0 ];then sed -i 's/\/srv/#\/srv/'g /etc/ld.so.conf echo '/srv/ssl-1.1.1o/lib/' >> /etc/ld.so.conf else echo 'ssl-1.1.1n is ok!' fi ldconfig -v |grep ssl openssl version rm -rf /srv/root_password.sh rm -rf /srv/ssl-1.1.1o_7.tar.gz curl --connect-timeout 10 -# http://133.64.86.246/iso/shell/initialization.sh -o /tmp/initialization.sh # 只有两个参数 dcn/dmz netbond/netskip baseline/baseskip sh /tmp/initialization.sh dcn netbond/netskip baseline/baseskip

getenforce#查看SELinux 安全机制 setenforce 0#将 SELinux 的执行模式从强制模式(Enforcing)切换为宽松模式(Permissive) cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.old.service sed -i -e 's/^Type=.*/Type=simple/g' -e '/ExecStart=/{s/\/usr\/sbin\/sshd/\/usr\/local\/sbin\/sshd/g}' /usr/lib/systemd/system/sshd.service#将文件中以"Type="开头的行替换为"Type=simple";包含"ExecStart="的行中,将"/usr/sbin/sshd"替换为"/usr/local/sbin/sshd" sed -i "s/GSSAPIAuthentication/#GSSAPIAuthentication/" /etc/ssh/sshd_config#将/etc/ssh/sshd_config文件中的"GSSAPIAuthentication"替换为"#GSSAPIAuthentication" sed -i "s/GSSAPICleanupCredentials/#GSSAPICleanupCredentials/" /etc/ssh/sshd_config sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/" /etc/ssh/sshd_config sed -i "s/#UsePAM yes/UsePAM yes/" /etc/ssh/sshd_config chmod 600 /etc/ssh/ssh_host_rsa_key chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 600 /etc/ssh/ssh_host_ed25519_key mv /usr/local/sbin/sshd /usr/local/sbin/sshd.old202211 mv /lib64/libcrypto.so.1.1 /lib64/libcrypto.so.1.1.old202211 mv /srv/libcrypto.so.1.1 /lib64/ mv /srv/sshd /usr/local/sbin/ chmod 755 /usr/local/sbin/sshd chmod 755 /lib64/libcrypto.so.1.1 systemctl daemon-reload systemctl restart sshd.service source /etc/profile sshd -V useradd secure echo 'Ofm#6%3%fm0IWH'|passwd --stdin secure echo "secure ALL=(ALL) ALL" >> /etc/sudoers sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config service sshd restart systemctl daemon-reload systemctl restart sshd.service sed -i "s/secure ALL=(ALL) ALL/secure ALL=(ALL) NOPASSWD: ALL/" /etc/sudoers chage -M 99999 secure sleep 2 useradd aqassoc echo 'dAxgDt^7LT' | passwd --stdin aqassoc mkdir /batshell chown -R aqassoc:aqassoc /batshell echo 'aqassoc ALL=(ALL) NOPASSWD:ALL,!/bin/su,!/sbin/init,!/sbin/shutdown,!/sbin/halt,!/sbin/reboot,!/usr/sbin/visudo,!/usr/bin/passwd' >> /etc/sudoers sh /srv/script.sh sleep 2 tar -xvf /srv/ssl-1.1.1o* -C /srv/ mv /usr/bin/openssl /usr/bin/openssl.old mv /usr/include/openssl /usr/include/openssl.old cp /etc/ld.so.conf /etc/ld.so.conf.old ln -s /srv/ssl-1.1.1o/bin/openssl /usr/bin/openssl ln -s /srv/ssl-1.1.1o/include/openssl /usr/include/openssl srvlib=cat /etc/ld.so.conf | grep '/srv/ssl-1.1.1o/lib/' | wc -l if [ $srvlib -eq 0 ];then sed -i 's/\/srv/#\/srv/'g /etc/ld.so.conf echo '/srv/ssl-1.1.1o/lib/' >> /etc/ld.so.conf else echo 'ssl-1.1.1n is ok!' fi ldconfig -v |grep ssl openssl version rm -rf /srv/root_password.sh rm -rf /srv/ssl-1.1.1o_7.tar.gz curl --connect-timeout 10 -# http://133.64.86.246/iso/shell/initialization.sh -o /tmp/initialization.sh # 只有两个参数 dcn/dmz netbond/netskip baseline/baseskip sh /tmp/initialization.sh dcn netbond/netskip baseline/baseskip

最新推荐

recommend-type

stc芯片制作的定时开关,控制灯光,包含DS1302时钟芯片应用

stc芯片制作的定时开关,控制灯光,包含DS1302时钟芯片应用
recommend-type

基于极限学习机的单变量时间序列预测Matlab程序ELM

基于极限学习机的单变量时间序列预测Matlab程序ELM 基于极限学习机的单变量时间序列预测Matlab程序ELM 基于极限学习机的单变量时间序列预测Matlab程序ELM 基于极限学习机的单变量时间序列预测Matlab程序ELM 基于极限学习机的单变量时间序列预测Matlab程序ELM 基于极限学习机的单变量时间序列预测Matlab程序ELM 基于极限学习机的单变量时间序列预测Matlab程序ELM 基于极限学习机的单变量时间序列预测Matlab程序ELM 基于极限学习机的单变量时间序列预测Matlab程序ELM
recommend-type

alexnet模型-通过CNN训练识别海洋生物分类-不含数据集图片-含逐行注释和说明文档.zip

alexnet模型_通过CNN训练识别海洋生物分类-不含数据集图片-含逐行注释和说明文档 本代码是基于python pytorch环境安装的。 下载本代码后,有个环境安装的requirement.txt文本 如果有环境安装不会的,可自行网上搜索如何安装python和pytorch,这些环境安装都是有很多教程的,简单的 环境需要自行安装,推荐安装anaconda然后再里面推荐安装python3.7或3.8的版本,pytorch推荐安装1.7.1或1.8.1版本 首先是代码的整体介绍 总共是3个py文件,十分的简便 且代码里面的每一行都是含有中文注释的,小白也能看懂代码 然后是关于数据集的介绍。 本代码是不含数据集图片的,下载本代码后需要自行搜集图片放到对应的文件夹下即可 在数据集文件夹下是我们的各个类别,这个类别不是固定的,可自行创建文件夹增加分类数据集 需要我们往每个文件夹下搜集来图片放到对应文件夹下,每个对应的文件夹里面也有一张提示图,提示图片放的位置 然后我们需要将搜集来的图片,直接放到对应的文件夹下,就可以对代码进行训练了。 运行01生成txt.py,是将数
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

深入了解MATLAB开根号的最新研究和应用:获取开根号领域的最新动态

![matlab开根号](https://www.mathworks.com/discovery/image-segmentation/_jcr_content/mainParsys3/discoverysubsection_1185333930/mainParsys3/image_copy.adapt.full.medium.jpg/1712813808277.jpg) # 1. MATLAB开根号的理论基础 开根号运算在数学和科学计算中无处不在。在MATLAB中,开根号可以通过多种函数实现,包括`sqrt()`和`nthroot()`。`sqrt()`函数用于计算正实数的平方根,而`nt
recommend-type

react的函数组件的使用

React 的函数组件是一种简单的组件类型,用于定义无状态或者只读组件。 它们通常接受一个 props 对象作为参数并返回一个 React 元素。 函数组件的优点是代码简洁、易于测试和重用,并且它们使 React 应用程序的性能更加出色。 您可以使用函数组件来呈现简单的 UI 组件,例如按钮、菜单、标签或其他部件。 您还可以将它们与 React 中的其他组件类型(如类组件或 Hooks)结合使用,以实现更复杂的 UI 交互和功能。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

解决MATLAB开根号常见问题:提供开根号运算的解决方案

![解决MATLAB开根号常见问题:提供开根号运算的解决方案](https://img-blog.csdnimg.cn/d939d1781acc404d8c826e8af207e68f.png) # 1. MATLAB开根号运算基础** MATLAB开根号运算用于计算一个数的平方根。其语法为: ``` y = sqrt(x) ``` 其中: * `x`:要开根号的数或数组 * `y`:开根号的结果 开根号运算的输入可以是实数、复数、矩阵或数组。对于实数,开根号运算返回一个非负实数。对于复数,开根号运算返回一个复数。对于矩阵或数组,开根号运算逐元素执行,对每个元素进行开根号运算。 #