首页
统计
友情链接
Search
1
python2.7的paramiko模块下载大文件失败
78 阅读
2
记一次客户端连接Docker容器 sshd 报错Permission denied, please try again.的问题
78 阅读
3
Python获取macbook用户名
74 阅读
4
Ubuntu 24.04 编译源码安装 Python 2.7
28 阅读
5
Centos 7.9.2009 ARM版本安装ssh
25 阅读
Python
Linux
登录
Search
标签搜索
python
macbook
pyhton
Ubuntu
python2.7
Ubuntu24
CentOS
SuperSu
累计撰写
5
篇文章
累计收到
12
条评论
首页
栏目
Python
Linux
页面
统计
友情链接
搜索到
5
篇与
的结果
2024-12-02
Centos 7.9.2009 ARM版本安装ssh
前言CentOS(Community Enterprise Operating System,中文意思是社区企业操作系统)是Linux发行版之一,是免费的、开源的、可以重新分发的开源操作系统。遇到问题产品需要支持ARM架构,但是CentOS ARM版本 装好以后并不能成功安装软件,安装ssh时报错如下:[root@3f0492e1adc1 /]# yum install openssh-server Loaded plugins: fastestmirror, ovl Determining fastest mirrors Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=aarch64&repo=os&infra=container error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error" One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable <repoid> or subscription-manager repos --disable=<repoid> 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: base/7/aarch64原因是因为无法从 CentOS 镜像列表服务器(http://mirrorlist.centos.org/?release=7&arch=aarch64&repo=os&infra=container)检索镜像列表,我们手动访问发现也无法请求。解决方案首先备份原来的源配置文件mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak然后下载新的源配置文件替换旧配置文件curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-altarch-7.repo然后执行命令yum clean all最后执行安装命令成功安装yum install openssh-server
2024年12月02日
25 阅读
0 评论
0 点赞
2024-11-08
Ubuntu 24.04 编译源码安装 Python 2.7
前言Ubuntu是世界上最流行的Linux系统之一,比Ubuntu更大的是自由软件,而比自由软件更大的则是自由软件的社区。Ubuntu社区为其使用者提供了多种学习、交流、切磋和讨论方式,如论坛、星球、维基及IRC即时通信等。通过Ubuntu庞大的社区组织,Ubuntu用户可以获得很多帮助和支持,使得Ubuntu使用起来更加得心应手。遇到问题项目需要更换系统底座为Ubuntu24.04,但是Ubuntu 24.04 对 Python 2.7 的维护已经停止了,因此 Python 2.7 已从 Ubuntu 24.04 软件包移除。如果想要安装 Python 2.7,需要我们自己从 Python官网 下载 Python 源码并编译。解决方案获取源码# 下载源码压缩包 wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tar.xz # 解压 tar -xJf Python-2.7.18.tar.xz安装依赖#提供了编译源码所需的基本工具和库 apt-get install build-essential编译安装cd Python-2.7.18 # 检查系统依赖是否满足编译所需 ./configure # 编译 安装 make && make install注意事项如果在执行./configure之前未安装依赖则会报错root@user:/home/path/packs/Python-2.7.18# ./configure checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python2.7... no checking for python3... python3 checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... linux2 checking EXTRAPLATDIR... checking for --without-gcc... no checking for --with-icc... no checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/home/path/packs/Python-2.7.18': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
2024年11月08日
28 阅读
3 评论
0 点赞
2024-03-25
记一次客户端连接Docker容器 sshd 报错Permission denied, please try again.的问题
背景在一次需求中需要实现 Docker 启动 CentOS7.9,并在容器内安装 sshd 实现外部客户端可以访问。sshd 是打包好可直接运行的二进制文件,并且 sshd_config 也是提供的现成的,这也为后边出现问题做了铺垫。我这边首先是把 sshd 的二进制可执行文件拷贝到了/usr/sbin/sshd,然后 sshd_config 拷贝到了/etc/ssh/sshd_config。{dotted startColor="#ff6c6c" endColor="#1989fa"/}报错与解决方案第一次执行,由于使用的 Docker 容器启动,并且 CMD命令为/bin/bash,所以只能通过启动二进制文件来操作。/usr/sbin/sshd报错{message type="error" content="Privilege separation user sshd does not exist"/}这是因为没有创建sshd用户,解决方案:/usr/sbin/groupadd sshd /usr/sbin/useradd -g sshd sshd再次启动报错如下:{message type="error" content="Could not load host key: /etc/ssh/ssh_host_rsa_keyCould not load host key: /etc/ssh/ssh_host_ecdsa_keyCould not load host key: /etc/ssh/ssh_host_ed25519_keysshd: no hostkeys available -- exiting."/}这是因为配置文件中设置了包含计算机私人密钥的文件HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key解决方案:1、询问 sshd_config 提供人,让他提供密钥文件2、使用sshd-keygen -A生成密钥再次启动报错如下:{message type="error" content="Permissions 0777 for '/etc/ssh/ssh_host_rsa_key' are too open.It is required that your private key files are NOT accessible by others.This private key will be ignored.key_load_private: bad permissions"/}这是因为配置文件权限过高,解决方案:chmod 600 /etc/ssh/*key*继续启动成功,客户端远程连接失败,报错:{message type="error" content="Permission denied, please try again."/}到这里就比较棘手了,一直没有找到解决办法,本身对于 sshd 的启动命令也不是很熟,后来得知可以通过使用 -d 参数前台启动并开启 debug 模式,终于燃起了一丝希望。首先服务端通过命令/usr/sbin/sshd -d启动客户端此时连接服务端,日志就会显示在前台页面,从中看到了一条报错:{message type="error" content="PAM: password authentication failed for root: Authentication failure"/}果断搜索此报错,终于找到了解决方案,参考https://blog.csdn.net/Daphnisz/article/details/124040904原因是我的配置文件中开启了UsePAM yes,配置文件是现成的,也就没注意到。解决方案:在 pam 中增加 sshd 的配置vim /etc/pam.d/sshd # 文件内容如下 #%PAM-1.0 auth required pam_sepermit.so auth substack password-auth auth include postlogin # Used with polkit to reauthorize users in remote sessions -auth optional pam_reauthorize.so prepare account required pam_nologin.so account include password-auth password include password-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open env_params session required pam_namespace.so session optional pam_keyinit.so force revoke session include password-auth session include postlogin # Used with polkit to reauthorize users in remote sessions -session optional pam_reauthorize.so prepare然后使用命令 ps aux | grep sshd 查看进程并 kill,重新启动/usr/sbin/sshd -d{dotted startColor="#ff6c6c" endColor="#1989fa"/}客户端重新连接成功,喜大普奔!!!
2024年03月25日
78 阅读
0 评论
0 点赞
2024-03-25
python2.7的paramiko模块下载大文件失败
编程中需要用到 Python(2.7) 的 paramiko 模块下载服务器上面一个比较大的文件,命令如下:client = paramiko.Transport(ip, port) client.connect(username=user, password=password) sftp = paramiko.SFTPClient.from_transport(client) sftp.get(remotefile, localfile)发现一个很奇怪的现象,下载比较小的文件时,没有发现异常,直到有一次下载一个 300mb+的文件时,中途卡住一直下载不下来解决方案:修改 python 有关 sftp 数据下载的源码,文件位置为:/usr/lib/python2.7/site-packages/paramiko/sftp_file.py找到_prefetch_thread 函数:def _prefetch_thread(self, chunks): # do these read requests in a temporary thread because there may be # a lot of them, so it may block. for offset, length in chunks: num = self.sftp._async_request( self, CMD_READ, self.handle, long(offset), int(length)) with self._prefetch_lock: self._prefetch_extents[num] = (offset, length)代码作者注释说明了此处可能存在并发过大的问题,所以我们对他进行修改:def _prefetch_thread(self, chunks): # do these read requests in a temporary thread because there may be # a lot of them, so it may block. max_request_num = 512 to_wait = False for offset, length in chunks: num = self.sftp._async_request( self, CMD_READ, self.handle, long(offset), int(length) ) with self._prefetch_lock: self._prefetch_extents[num] = (offset, length) if len(self._prefetch_extents) >= max_request_num: to_wait = True if to_wait: time.sleep(1) to_wait = False总体思路就是限制同时存在的异步请求总数
2024年03月25日
78 阅读
3 评论
0 点赞
2024-03-20
Python获取macbook用户名
在做一个PyQt5项目时需要将文件保存至macbook 的桌面文件夹内,路径如下:/Users/supersu/Desktop/anti-capitalism/result 观看路径可知,绝对路径中存在用户名:supersu 那我们如何通过 Python 获取这个用户名呢?可以用到 python 自带的getpass 模块,执行以下代码即可获取:import getpass user_name = getpass.getuser() # supersu
2024年03月20日
74 阅读
5 评论
0 点赞